Class: UboostClient::Account
- Inherits:
-
Object
- Object
- UboostClient::Account
- Defined in:
- lib/uboost-client/uboost_client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #create(data) ⇒ Object
- #delete(account_id) ⇒ Object
- #find(query) ⇒ Object
-
#initialize(client) ⇒ Account
constructor
A new instance of Account.
- #points_transactions(account_id, options = nil) ⇒ Object
- #select(account_id) ⇒ Object
- #token(id) ⇒ Object
- #update(account_id, hash) ⇒ Object
Constructor Details
#initialize(client) ⇒ Account
Returns a new instance of Account.
63 64 65 66 |
# File 'lib/uboost-client/uboost_client.rb', line 63 def initialize(client) @client = client @url = '/api/accounts' end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
61 62 63 |
# File 'lib/uboost-client/uboost_client.rb', line 61 def client @client end |
#url ⇒ Object
Returns the value of attribute url.
61 62 63 |
# File 'lib/uboost-client/uboost_client.rb', line 61 def url @url end |
Instance Method Details
#create(data) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/uboost-client/uboost_client.rb', line 68 def create(data) data = {'account' => data} 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 |
#delete(account_id) ⇒ Object
93 94 95 96 |
# File 'lib/uboost-client/uboost_client.rb', line 93 def delete(account_id) response = client.connection.delete "#{@url}/#{account_id}" OpenStruct.new(JSON.parse(response.body)) end |
#find(query) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/uboost-client/uboost_client.rb', line 98 def find(query) response = client.connection.get do |req| req.url @url + "/find", query end OpenStruct.new(JSON.parse(response.body)) end |
#points_transactions(account_id, options = nil) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/uboost-client/uboost_client.rb', line 110 def points_transactions(account_id, = nil) response = client.connection.get do |req| req.url @url + "/#{account_id}/points_transactions", end OpenStruct.new(JSON.parse(response.body)) end |
#select(account_id) ⇒ Object
78 79 80 81 |
# File 'lib/uboost-client/uboost_client.rb', line 78 def select(account_id) response = client.connection.get "#{@url}/#{account_id}" OpenStruct.new(JSON.parse(response.body)) end |
#token(id) ⇒ Object
105 106 107 108 |
# File 'lib/uboost-client/uboost_client.rb', line 105 def token(id) response = client.connection.get "#{@url}/#{id}/sign_in_user" OpenStruct.new(JSON.parse(response.body)) end |
#update(account_id, hash) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/uboost-client/uboost_client.rb', line 83 def update(account_id, hash) data = {'account' => hash} response = client.connection.put do |req| req.url "#{@url}/#{account_id}" req.headers['Content-Type'] = 'application/json' req.body = JSON.generate(data) end OpenStruct.new(JSON.parse(response.body)) end |