Class: Yieldmanager::Client

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

Overview

This is the frontend for using Yieldmanager programmatically. It can be directly used by the user by creating a new instance and calling service_name to access YM services. For example:

ym = Yieldmanager::Client(

:user => "bob",
:pass => "secret",
:api_version => "1.30"

)

ym.session do |token|

currencies = @ym.dictionary.getCurrencies(token)

end

Constant Summary collapse

BASE_URL =
"https://api.yieldmanager.com/api-"
BASE_URL_TEST =
"https://api-test.yieldmanager.com/api-"
WSDL_DIR =
File.join(File.dirname(__FILE__), '..', '..', 'wsdls')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Client

Creates interface object.

Options:

  • :user (required) - Yieldmanager user

  • :pass (required) - Yieldmanager pass

  • :api_version (required) - Yieldmanager API version (i.e., “1.30”)

  • :env (optional) - Yieldmanager environment “prod” or “test” (defaults to prod)



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/yieldmanager/client.rb', line 41

def initialize(options = nil)
  unless options && options[:user] && options[:pass] && options[:api_version]
    raise ArgumentError, ":user, :pass and :api_version are required"
  end
  @user = options[:user]
  @pass = options[:pass]
  @api_version = options[:api_version]
  @env = options[:env] ||= "prod"
  @wsdl_dir = "#{WSDL_DIR}/#{@api_version}/#{@env}"
  wrap_services
end

Instance Attribute Details

#api_versionObject (readonly)

Yieldmanager api version (i.e., “1.30”)



27
28
29
# File 'lib/yieldmanager/client.rb', line 27

def api_version
  @api_version
end

#envObject (readonly)

Yieldmanager environment (“prod” or “test”, defaults to “prod”)



29
30
31
# File 'lib/yieldmanager/client.rb', line 29

def env
  @env
end

#passObject (readonly)

Yieldmanager password



25
26
27
# File 'lib/yieldmanager/client.rb', line 25

def pass
  @pass
end

#userObject (readonly)

Yieldmanager user



23
24
25
# File 'lib/yieldmanager/client.rb', line 23

def user
  @user
end

Instance Method Details

#available_servicesObject



53
54
55
56
57
58
59
60
61
# File 'lib/yieldmanager/client.rb', line 53

def available_services
  Dir.entries(@wsdl_dir).map do |wsdl|
    if wsdl.match(/wsdl/) 
      wsdl.sub(/\.wsdl/,'')
    else
      nil
    end
  end.compact
end

#end_session(token) ⇒ Object

Closes Yieldmanager session



69
70
71
# File 'lib/yieldmanager/client.rb', line 69

def end_session token
  contact.logout(token)
end

#paginate(block_size) ⇒ Object

Allows looping over datasets too large to pull back in one call

Block must return total rows in dataset to know when to stop!



86
87
88
89
90
91
92
93
94
# File 'lib/yieldmanager/client.rb', line 86

def paginate block_size
  page = 1
  total = block_size + 1

  begin
    total = yield page # Need total back from block to know when to stop!
    page += 1
  end until (block_size * (page-1)) > total
end

#sessionObject

Manages Yieldmanager session



74
75
76
77
78
79
80
81
# File 'lib/yieldmanager/client.rb', line 74

def session
  token = start_session
  begin
    yield token
  ensure
    end_session token
  end
end

#start_sessionObject

Opens Yieldmanager session



64
65
66
# File 'lib/yieldmanager/client.rb', line 64

def start_session
  contact.(@user,@pass,{'errors_level' => 'throw_errors','multiple_sessions' => '1'})
end