Class: UboostClient::Badges

Inherits:
Object
  • Object
show all
Defined in:
lib/uboost-client/uboost_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Badges

Returns a new instance of Badges.



149
150
151
152
# File 'lib/uboost-client/uboost_client.rb', line 149

def initialize(client)
  @client = client
  @url = '/api/badges'
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



147
148
149
# File 'lib/uboost-client/uboost_client.rb', line 147

def client
  @client
end

#urlObject

Returns the value of attribute url.



147
148
149
# File 'lib/uboost-client/uboost_client.rb', line 147

def url
  @url
end

Instance Method Details

#award(account_id, badge_type_id, options = nil) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/uboost-client/uboost_client.rb', line 154

def award(, badge_type_id, options = nil)
  data = {:badge => {:account_id => , :badge_type_id => badge_type_id}}
  data[:badge].merge!(options) if options
  response = client.connection.post do |req|
    req.url @url
    req.headers['Content-Type'] = 'application/json'
    req.body = JSON.generate(data)
  end
  OpenStruct.new(JSON.parse(response.body))
end

#unaward(account_id, badge_type_id, options = nil) ⇒ Object



165
166
167
168
169
170
171
172
173
174
# File 'lib/uboost-client/uboost_client.rb', line 165

def unaward(, badge_type_id, options = nil)
  data = {:badge => {:account_id => , :badge_type_id => badge_type_id}}
  data[:badge].merge!(options) if options
  response = client.connection.delete do |req|
    req.url @url + "/unaward"
    req.headers['Content-Type'] = 'application/json'
    req.body = JSON.generate(data)
  end
  OpenStruct.new(JSON.parse(response.body))
end