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.



154
155
156
157
# File 'lib/uboost-client/uboost_client.rb', line 154

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



152
153
154
# File 'lib/uboost-client/uboost_client.rb', line 152

def client
  @client
end

#urlObject

Returns the value of attribute url.



152
153
154
# File 'lib/uboost-client/uboost_client.rb', line 152

def url
  @url
end

Instance Method Details

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



159
160
161
162
163
164
165
166
167
168
# File 'lib/uboost-client/uboost_client.rb', line 159

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



170
171
172
173
174
175
176
177
178
179
# File 'lib/uboost-client/uboost_client.rb', line 170

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