Class: OpenTransact::Client
- Inherits:
-
Object
- Object
- OpenTransact::Client
- Defined in:
- lib/opentransact/client.rb
Overview
The main OpenTransact client access point. It wraps around an OAuth Token.
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#secret ⇒ Object
writeonly
Sets the attribute secret.
-
#server ⇒ Object
Returns the value of attribute server.
-
#site ⇒ Object
Returns the value of attribute site.
-
#token ⇒ Object
writeonly
Sets the attribute token.
Instance Method Summary collapse
-
#access_token ⇒ Object
returns an oauth access token.
-
#assets ⇒ Object
returns the assets on a particular server.
- #delete(path) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(*params) ⇒ Client
constructor
Create a client:.
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
-
#wallet ⇒ Object
returns the assets on the server for a particular client.
- #wallet_list ⇒ Object
Constructor Details
#initialize(*params) ⇒ Client
Create a client:
# no oauth
@client = OpenTransact::Client.new "http://picomoney.com"
# with oauth credentials
@client = OpenTransact::Client.new "https://picomoney.com",
:token => "my token", :secret => "my secret",
:consumer_key => "consumer key", :consumer_secret => "consumer secret"
# with pre initialized server
@client = OpenTransact::Client.new "https://picomoney.com",
> :server => @server,
:token => "my token", :secret => "my secret"
24 25 26 27 28 |
# File 'lib/opentransact/client.rb', line 24 def initialize(*params) @options = params.pop if params.last.is_a?(Hash) @options ||= {} @site = params.first || [:site] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/opentransact/client.rb', line 7 def @options end |
#secret=(value) ⇒ Object
Sets the attribute secret
7 8 9 |
# File 'lib/opentransact/client.rb', line 7 def secret=(value) @secret = value end |
#server ⇒ Object
Returns the value of attribute server.
7 8 9 |
# File 'lib/opentransact/client.rb', line 7 def server @server end |
#site ⇒ Object
Returns the value of attribute site.
7 8 9 |
# File 'lib/opentransact/client.rb', line 7 def site @site end |
#token=(value) ⇒ Object
Sets the attribute token
7 8 9 |
# File 'lib/opentransact/client.rb', line 7 def token=(value) @token = value end |
Instance Method Details
#access_token ⇒ Object
returns an oauth access token
31 32 33 |
# File 'lib/opentransact/client.rb', line 31 def access_token @access_token ||= OAuth::AccessToken.new server.consumer, token, secret if server end |
#assets ⇒ Object
returns the assets on a particular server
36 37 38 |
# File 'lib/opentransact/client.rb', line 36 def assets [] end |
#delete(path) ⇒ Object
59 60 61 |
# File 'lib/opentransact/client.rb', line 59 def delete(path) parse(access_token.delete(path, {'Accept' => 'application/json'})) end |
#get(path) ⇒ Object
67 68 69 |
# File 'lib/opentransact/client.rb', line 67 def get(path) parse(access_token.get(path, {'Accept' => 'application/json'})) end |
#post(path, params = {}) ⇒ Object
63 64 65 |
# File 'lib/opentransact/client.rb', line 63 def post(path,params={}) parse(access_token.post(path,params, {'Accept' => 'application/json'})) end |
#put(path, params = {}) ⇒ Object
55 56 57 |
# File 'lib/opentransact/client.rb', line 55 def put(path,params={}) parse(access_token.put(path,params, {'Accept' => 'application/json'})) end |
#wallet ⇒ Object
returns the assets on the server for a particular client
41 42 43 44 45 |
# File 'lib/opentransact/client.rb', line 41 def wallet @wallet ||= wallet_list.collect do |a| OpenTransact::Asset.new(a.delete("url"),a.merge({:client=>self})) end end |
#wallet_list ⇒ Object
47 48 49 |
# File 'lib/opentransact/client.rb', line 47 def wallet_list @wallet_list ||= get(server.rel_link("http://opentransact.org/rel/wallet"))["assets"] ||[] end |