cobot_client 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/cobot_client.gemspec CHANGED
@@ -15,7 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = CobotClient::VERSION
17
17
 
18
- gem.add_dependency 'activesupport'
19
18
  gem.add_dependency 'virtus'
20
19
  gem.add_dependency 'oauth2'
21
20
  gem.add_dependency 'rest-client'
@@ -25,8 +25,6 @@ module CobotClient
25
25
  delete subdomain, "/bookings/#{id}"
26
26
  end
27
27
 
28
- private
29
-
30
28
  def put(subdomain, path, params)
31
29
  JSON.parse RestClient.put(cobot_url(subdomain, "/api#{path}"), params, auth_headers).body,
32
30
  symbolize_names: true
@@ -41,9 +39,9 @@ module CobotClient
41
39
  symbolize_names: true
42
40
  end
43
41
 
44
- def get(subdomain, path)
42
+ def get(subdomain, path, params = {})
45
43
  JSON.parse(
46
- RestClient.get(cobot_url(subdomain, "/api#{path}"), auth_headers).body,
44
+ RestClient.get(cobot_url(subdomain, "/api#{path}", params: params), auth_headers).body,
47
45
  symbolize_names: true
48
46
  )
49
47
  end
@@ -1,9 +1,16 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
1
  require 'uri'
3
2
 
4
3
  module CobotClient::UrlHelper
5
4
  # set this to override the site for accessing the cobot api
6
- mattr_accessor :site
5
+
6
+ @@site = 'https://www.cobot.me'
7
+ def self.site
8
+ @@site
9
+ end
10
+
11
+ def self.site=(site)
12
+ @@site = site
13
+ end
7
14
 
8
15
  # generates a url to access the cobot api
9
16
  # see the spec for usage examples
@@ -11,10 +18,10 @@ module CobotClient::UrlHelper
11
18
  path = path_options.first.is_a?(String) ? path_options.first : '/'
12
19
  options = path_options.find{|p| p.is_a?(Hash)} || {}
13
20
 
14
- url = URI.parse(site || 'https://www.cobot.me')
21
+ url = URI.parse(CobotClient::UrlHelper.site)
15
22
  url.host = url.host.split('.').tap{|parts| parts[0] = subdomain}.join('.')
16
23
  url.path = path
17
- url.query = URI.encode_www_form(options[:params]) if options[:params]
24
+ url.query = URI.encode_www_form(options[:params]) if options[:params] && options[:params].any?
18
25
 
19
26
  url.to_s
20
27
  end
@@ -1,3 +1,3 @@
1
1
  module CobotClient
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -65,4 +65,19 @@ describe CobotClient::ApiClient do
65
65
  api_client.delete_booking 'co-up', 'booking-1'
66
66
  end
67
67
  end
68
+
69
+ context '#get' do
70
+ it 'calls rest client' do
71
+ RestClient.should_receive(:get).with('https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12',
72
+ 'Authorization' => 'Bearer token-123') { default_response }
73
+
74
+ api_client.get 'co-up', '/invoices', {from: '2013-10-6', to: '2013-10-12'}
75
+ end
76
+
77
+ it 'returns the response json' do
78
+ RestClient.stub(:get) { stub(:response, body: [{number: 1}].to_json) }
79
+
80
+ expect(api_client.get('co-up', '/invoices')).to eql([{number: 1}])
81
+ end
82
+ end
68
83
  end
@@ -7,6 +7,16 @@ describe CobotClient::UrlHelper, 'cobot_url' do
7
7
  end
8
8
  end
9
9
 
10
+ after(:each) do
11
+ CobotClient::UrlHelper.site = 'https://www.cobot.me'
12
+ end
13
+
14
+ it 'lets me change the site' do
15
+ CobotClient::UrlHelper.site = 'https://www.cobot.com'
16
+
17
+ expect(helper.cobot_url).to eql('https://www.cobot.com/')
18
+ end
19
+
10
20
  it 'returns the default url' do
11
21
  expect(helper.cobot_url).to eql('https://www.cobot.me/')
12
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cobot_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-30 00:00:00.000000000 Z
12
+ date: 2013-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: activesupport
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: virtus
32
16
  requirement: !ruby/object:Gem::Requirement