Class: Datumfactory::Events
- Inherits:
-
Object
- Object
- Datumfactory::Events
- Includes:
- HTTParty
- Defined in:
- lib/datumfactory.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #by_slug(id) ⇒ Object
- #create(data, title, slug, description = nil) ⇒ Object
- #destroy(id) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(site, email, password) ⇒ Events
constructor
A new instance of Events.
- #login ⇒ Object
Constructor Details
#initialize(site, email, password) ⇒ Events
Returns a new instance of Events.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/datumfactory.rb', line 42 def initialize(site, email, password) self.class.base_uri "#{site}.datumfactory.com" @site = site @email = email @password = password = { headers: { 'Content-Type' => 'application/json' } } end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
13 14 15 |
# File 'lib/datumfactory.rb', line 13 def auth_token @auth_token end |
Class Method Details
.capture_event(site, auth_token, data, title, slug, description = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/datumfactory.rb', line 18 def self.capture_event(site, auth_token, data, title, slug, description = nil) body = { query: { event: { data: data, title: title, description: description, slug: slug } } } = { headers: { 'Content-Type' => 'application/json', 'X-API-Key' => auth_token.to_s } } .merge!(body) base_uri "https://#{site}.datumfactory.com" post('/api/v1/events', ).parsed_response end |
Instance Method Details
#all ⇒ Object
68 69 70 |
# File 'lib/datumfactory.rb', line 68 def all self.class.get('/api/v1/events', .merge({ headers: { 'Authorization' => "Bearer #{@auth_token}" } })).parsed_response end |
#by_slug(id) ⇒ Object
76 77 78 |
# File 'lib/datumfactory.rb', line 76 def by_slug(id) self.class.get("/api/v1/events/by-slug/#{id}", .merge({ headers: { 'Authorization' => "Bearer #{@auth_token}" } })).parsed_response end |
#create(data, title, slug, description = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/datumfactory.rb', line 80 def create(data, title, slug, description = nil) body = { query: { event: { data: data, title: title, description: description, slug: slug } } } .merge!({ headers: { 'Authorization' => "Bearer #{@auth_token}" } }) .merge!(body) self.class.post('/api/v1/events', ).parsed_response end |
#destroy(id) ⇒ Object
72 73 74 |
# File 'lib/datumfactory.rb', line 72 def destroy(id) self.class.delete("/api/v1/events/#{id}", .merge({ headers: { 'Authorization' => "Bearer #{@auth_token}" } })) end |
#get(id) ⇒ Object
64 65 66 |
# File 'lib/datumfactory.rb', line 64 def get(id) self.class.get("/api/v1/events/#{id}", .merge({ headers: { 'Authorization' => "Bearer #{@auth_token}" } })).parsed_response end |
#login ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/datumfactory.rb', line 54 def login result = self.class.post('/api/login', .merge( query: { "email": @email, "password": @password } )) @auth_token = result['auth_token'] end |