centro-client 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,14 +8,14 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Centro::Client::VERSION
9
9
  gem.authors = ["Tim Galeckas"]
10
10
  gem.email = ["tim@galeckas.com"]
11
- gem.description = %q{Ruby Client for the Centro api}
12
- gem.summary = %q{Ruby Client for the Centro api}
11
+ gem.description = %q{Ruby Client for the Centro API}
12
+ gem.summary = %q{Ruby Client for the Centro API}
13
13
  gem.homepage = "http://github.com/centro/centro.rb"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
18
+ gem.require_paths = ['lib']
19
19
 
20
20
  gem.add_development_dependency 'rspec'
21
21
  gem.add_development_dependency 'webmock'
@@ -20,6 +20,12 @@ module Centro
20
20
  raise adapt_error(e)
21
21
  end
22
22
 
23
+ def planner(method, *args)
24
+ planner_connection.send(method, *args)
25
+ rescue Exception => e
26
+ raise adapt_error(e)
27
+ end
28
+
23
29
  private
24
30
 
25
31
  def adapt_error(e)
data/lib/centro/client.rb CHANGED
@@ -12,31 +12,72 @@ module Centro
12
12
  return @api_version if defined?(@api_version)
13
13
  @api_version = 'v1'
14
14
  end
15
+
16
+ def api_version=(api_version)
17
+ @api_version = api_version
18
+ end
19
+
15
20
  def auth_host
16
21
  return @auth_host if defined?(@auth_host)
17
- @auth_host = 'localhost:3001'
22
+ @auth_host = 'accounts.centro.net'
18
23
  end
24
+
25
+ def auth_host=(auth_host)
26
+ @auth_host = auth_host
27
+ end
28
+
19
29
  def finance_host
20
30
  return @finance_host if defined?(@finance_host)
21
- @finance_host = 'localhost:4000'
31
+ @finance_host = 'finance.transis.com'
22
32
  end
33
+
34
+ def finance_host=(finance_host)
35
+ @finance_host = finance_host
36
+ end
37
+
23
38
  def mms_host
24
39
  return @mms_host if defined?(@mms_host)
25
- @mms_host = 'localhost:3000'
40
+ @mms_host = 'the.centro.net'
41
+ end
42
+
43
+ def mms_host=(mms_host)
44
+ @mms_host = mms_host
26
45
  end
46
+
47
+ def planner_host
48
+ return @planner_host if defined?(@planner_host)
49
+ @planner_host = 'planner.centro.net'
50
+ end
51
+
52
+ def planner_host=(planner_host)
53
+ @planner_host = planner_host
54
+ end
55
+
27
56
  def ssl_enabled?
28
57
  return @ssl_enabled if defined?(@ssl_enabled)
29
- @ssl_enaabled = false
58
+ @ssl_enabled = true
30
59
  end
60
+
61
+ def ssl_enabled=(ssl_enabled)
62
+ @ssl_enabled = ssl_enabled
63
+ end
64
+
31
65
  def auth_url
32
66
  url_from_host(auth_host)
33
67
  end
68
+
34
69
  def finance_url
35
70
  url_from_host(finance_host)
36
71
  end
72
+
37
73
  def mms_url
38
74
  url_from_host(mms_host)
39
75
  end
76
+
77
+ def planner_url
78
+ url_from_host(planner_host)
79
+ end
80
+
40
81
  def url_from_host(host)
41
82
  (ssl_enabled? ? 'https://' : 'http://') +
42
83
  host + "/api/#{self.api_version}"
@@ -49,6 +90,17 @@ module Centro
49
90
  @client_id = opts.delete(:client_id) if opts[:client_id]
50
91
  @client_secret = opts.delete(:client_secret) if opts[:client_secret]
51
92
  @access_token = opts.delete(:access_token) if opts[:access_token]
93
+ @basic_auth_username = opts.delete(:basic_auth_username) if opts[:basic_auth_username]
94
+ @basic_auth_password = opts.delete(:basic_auth_password) if opts[:basic_auth_password]
95
+ end
96
+
97
+ def fetch(url)
98
+ connection(url).get.body
99
+ end
100
+
101
+ # Data will be JSON-ified if it's not already in string-form
102
+ def put(url, data)
103
+ connection(url).put("", data).body
52
104
  end
53
105
 
54
106
  def access_token_expired?
@@ -57,9 +109,11 @@ module Centro
57
109
 
58
110
  def retrieve_access_token(username, password)
59
111
  raise 'client_id and client_secret required' unless @client_id && @client_secret
60
- connection = Faraday.new self.class.auth_url do |conn|
112
+
113
+ connection = Faraday.new(self.class.auth_url) do |conn|
61
114
  set_default_connection_options(conn)
62
115
  end
116
+
63
117
  response = connection.post('/oauth/token',
64
118
  :grant_type => 'password',
65
119
  :client_id => @client_id,
@@ -77,7 +131,7 @@ module Centro
77
131
 
78
132
  def get_organizations(user_id=nil)
79
133
  options = {}
80
- options[:user_id]=user_id if user_id
134
+ options[:user_id] = user_id if user_id
81
135
  auth_connection.get("organizations.json", options).body
82
136
  end
83
137
 
@@ -127,30 +181,35 @@ module Centro
127
181
 
128
182
  def auth_connection
129
183
  raise 'access_token required' unless @access_token
130
- @auth_connection ||= begin
131
- Faraday.new self.class.auth_url do |conn|
132
- conn.request :oauth2, @access_token
133
- set_default_connection_options(conn)
134
- end
135
- end
184
+ @auth_connection ||= connection(self.class.auth_url)
136
185
  end
186
+
137
187
  def finance_connection
138
188
  raise 'access_token required' unless @access_token
139
- @finance_connection ||= begin
140
- Faraday.new self.class.finance_url do |conn|
141
- conn.request :oauth2, @access_token
142
- set_default_connection_options(conn)
143
- end
144
- end
189
+ @finance_connection ||= connection(self.class.finance_url)
145
190
  end
191
+
146
192
  def mms_connection
147
193
  raise 'access_token required' unless @access_token
148
- @mms_connection ||= begin
149
- Faraday.new self.class.mms_url do |conn|
150
- conn.request :oauth2, @access_token
151
- set_default_connection_options(conn)
152
- end
194
+ @mms_connection ||= connection(self.class.mms_url)
195
+ end
196
+
197
+ def planner_connection
198
+ raise 'basic_auth_username required' unless @basic_auth_username
199
+ raise 'basic_auth_password required' unless @basic_auth_password
200
+ @planner_connection ||= Faraday.new(self.class.planner_url) do |conn|
201
+ conn.basic_auth(@basic_auth_username, @basic_auth_password)
202
+ set_default_connection_options(conn)
203
+ end
204
+ end
205
+
206
+ def connection(url)
207
+ raise 'access_token required' unless @access_token
208
+ Faraday.new url do |conn|
209
+ conn.request :oauth2, @access_token
210
+ set_default_connection_options(conn)
153
211
  end
154
212
  end
213
+
155
214
  end
156
215
  end
@@ -1,5 +1,5 @@
1
1
  module Centro
2
2
  class Client
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: centro-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Galeckas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-27 00:00:00 Z
18
+ date: 2013-01-03 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -129,7 +129,7 @@ dependencies:
129
129
  version: "0"
130
130
  type: :runtime
131
131
  version_requirements: *id008
132
- description: Ruby Client for the Centro api
132
+ description: Ruby Client for the Centro API
133
133
  email:
134
134
  - tim@galeckas.com
135
135
  executables: []
@@ -179,6 +179,6 @@ rubyforge_project:
179
179
  rubygems_version: 1.8.15
180
180
  signing_key:
181
181
  specification_version: 3
182
- summary: Ruby Client for the Centro api
182
+ summary: Ruby Client for the Centro API
183
183
  test_files: []
184
184