Class: Dopamine

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

Constant Summary collapse

HEADERS =
{
  'Accept' => 'application/json',
  'Content-Type' => 'application/x-www-form-urlencoded'
}

Instance Method Summary collapse

Constructor Details

#initialize(api_token, api_key, app_id, device_type = 3) ⇒ Dopamine

Returns a new instance of Dopamine.



18
19
20
21
22
23
24
# File 'lib/dopamine.rb', line 18

def initialize(api_token, api_key, app_id, device_type=3)
  @api_token = api_token
  @api_key = api_key
  @app_id = app_id
  @device_type = device_type
  HEADERS.merge!('User-Agent'=> "#{@app_id}")
end

Instance Method Details

#get_user(unique_id, id_type = 5) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/dopamine.rb', line 26

def get_user(unique_id, id_type=5)
  query = config.merge(
    'deviceType' => @device_type,
    'IDType' => id_type,
    'uniqueID' => unique_id
  )
  self.class.get('/user', query: query, headers: HEADERS)
end

#redeem(user_uri, hablet_id, email) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/dopamine.rb', line 44

def redeem(user_uri, hablet_id, email)
  body = config.merge(
    'deviceType' => @device_type,
    'userURI' => user_uri,
    'habletID' => hablet_id, 
    'email' => email
  )
  self.class.post("/user/#{user_uri}/app/#{@app_id}/", body: body, headers: HEADERS)
end

#reinforce?(user_uri, hablet_id) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
# File 'lib/dopamine.rb', line 35

def reinforce?(user_uri, hablet_id)
  query = config.merge(
    'deviceType' => @device_type,
    'userURI' => user_uri,
    'habletID' => hablet_id
  )
  self.class.get("/user/#{user_uri}/app/#{@app_id}", query: query, headers: HEADERS)
end