Class: Datumfactory::Events

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/datumfactory.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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
  @options = {
    headers: {
      'Content-Type' => 'application/json'
    }
  }
end

Instance Attribute Details

#auth_tokenObject (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
      }
    }
  }

  options = {
    headers: {
      'Content-Type' => 'application/json',
      'X-API-Key' => auth_token.to_s
    }
  }

  options.merge!(body)
  base_uri "https://#{site}.datumfactory.com"
  post('/api/v1/events', options).parsed_response
end

Instance Method Details

#allObject



68
69
70
# File 'lib/datumfactory.rb', line 68

def all
  self.class.get('/api/v1/events', @options.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}", @options.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
      }
    }
  }

  @options.merge!({ headers: { 'Authorization' => "Bearer #{@auth_token}" } })
  @options.merge!(body)
  self.class.post('/api/v1/events', @options).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}", @options.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}", @options.merge({ headers: { 'Authorization' => "Bearer #{@auth_token}" } })).parsed_response
end

#loginObject



54
55
56
57
58
59
60
61
62
# File 'lib/datumfactory.rb', line 54

def 
  result = self.class.post('/api/login', @options.merge(
                                           query: {
                                             "email": @email,
                                             "password": @password
                                           }
                                         ))
  @auth_token = result['auth_token']
end