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.



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

#clientObject

Returns the value of attribute client.



61
62
63
# File 'lib/uboost-client/uboost_client.rb', line 61

def client
  @client
end

#urlObject

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()
  response = client.connection.delete "#{@url}/#{}"
  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(, 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



78
79
80
81
# File 'lib/uboost-client/uboost_client.rb', line 78

def select()
  response = client.connection.get "#{@url}/#{}"
  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(, 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