class Datumfactory::Events

Attributes

auth_token[R]

Public Class Methods

capture_event(site, auth_token, data, title, slug, description = nil) click to toggle source
# 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
new(site, email, password) click to toggle source
# 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

Public Instance Methods

all() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
login() click to toggle source
# File lib/datumfactory.rb, line 54
def login
  result = self.class.post('/api/login', @options.merge(
                                           query: {
                                             "email": @email,
                                             "password": @password
                                           }
                                         ))
  @auth_token = result['auth_token']
end