Class: OpenTransact::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/opentransact/client.rb

Overview

The main OpenTransact client access point. It wraps around an OAuth Token.

Instance Attribute Summary collapse

Instance Method Summary collapse

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 || options[:site]
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/opentransact/client.rb', line 7

def options
  @options
end

#secret=(value) ⇒ Object

Sets the attribute secret

Parameters:

  • value

    the value to set the attribute secret to.



7
8
9
# File 'lib/opentransact/client.rb', line 7

def secret=(value)
  @secret = value
end

#serverObject

Returns the value of attribute server.



7
8
9
# File 'lib/opentransact/client.rb', line 7

def server
  @server
end

#siteObject

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

Parameters:

  • value

    the value to set the attribute token to.



7
8
9
# File 'lib/opentransact/client.rb', line 7

def token=(value)
  @token = value
end

Instance Method Details

#access_tokenObject

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

#assetsObject

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

#walletObject

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_listObject



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