Class: UboostClient::Account

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) ⇒ Account

Returns a new instance of Account.



58
59
60
61
# File 'lib/uboost-client/uboost_client.rb', line 58

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



56
57
58
# File 'lib/uboost-client/uboost_client.rb', line 56

def client
  @client
end

#urlObject

Returns the value of attribute url.



56
57
58
# File 'lib/uboost-client/uboost_client.rb', line 56

def url
  @url
end

Instance Method Details

#create(data) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/uboost-client/uboost_client.rb', line 63

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



88
89
90
91
# File 'lib/uboost-client/uboost_client.rb', line 88

def delete()
  response = client.connection.delete "#{@url}/#{}"
  OpenStruct.new(JSON.parse(response.body))
end

#find(query) ⇒ Object



93
94
95
96
97
98
# File 'lib/uboost-client/uboost_client.rb', line 93

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



105
106
107
108
109
110
# File 'lib/uboost-client/uboost_client.rb', line 105

def points_transactions(, options = nil)
  response = client.connection.get do |req|
    req.url @url + "/#{}/points_transactions", options
  end
  OpenStruct.new(JSON.parse(response.body))
end

#select(account_id) ⇒ Object



73
74
75
76
# File 'lib/uboost-client/uboost_client.rb', line 73

def select()
  response = client.connection.get "#{@url}/#{}"
  OpenStruct.new(JSON.parse(response.body))
end

#token(id) ⇒ Object



100
101
102
103
# File 'lib/uboost-client/uboost_client.rb', line 100

def token(id)
  response = client.connection.get "#{@url}/#{id}/sign_in_user"
  OpenStruct.new(JSON.parse(response.body))
end

#update(account_id, hash) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/uboost-client/uboost_client.rb', line 78

def update(, hash)
  data = {'account' => hash}
  response = client.connection.put do |req|
    req.url "#{@url}/#{}"
    req.headers['Content-Type'] = 'application/json'
    req.body = JSON.generate(data)
  end
  OpenStruct.new(JSON.parse(response.body))
end