plangrade-ruby 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.gitignore +2 -0
- data/.travis.yml +20 -0
- data/Gemfile +7 -0
- data/README.md +190 -53
- data/Rakefile +10 -1
- data/lib/plangrade/api/company.rb +4 -4
- data/lib/plangrade/api/participant.rb +6 -5
- data/lib/plangrade/api/user.rb +3 -3
- data/lib/plangrade/oauth2_client.rb +1 -0
- data/lib/plangrade/resources/company.rb +1 -1
- data/lib/plangrade/resources/participant.rb +2 -2
- data/lib/plangrade/resources/user.rb +3 -3
- data/lib/plangrade/ruby/version.rb +1 -1
- data/plangrade-ruby.gemspec +6 -10
- data/spec/api/company_spec.rb +72 -0
- data/spec/api/participant_spec.rb +79 -0
- data/spec/api/user_spec.rb +65 -0
- data/spec/client_spec.rb +332 -0
- data/spec/error_spec.rb +88 -0
- data/spec/fixtures/company.json +1 -0
- data/{test → spec}/fixtures/one_user.yml +0 -0
- data/spec/fixtures/participant.json +1 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/http_adapter_spec.rb +109 -0
- data/spec/oauth2_client_spec.rb +109 -0
- data/spec/resources/base_spec.rb +190 -0
- data/spec/resources/company_spec.rb +135 -0
- data/spec/resources/identity_map_spec.rb +127 -0
- data/spec/resources/participant_spec.rb +151 -0
- data/spec/resources/user_spec.rb +152 -0
- data/spec/spec_helper.rb +73 -0
- data/{test → spec}/user/user_test.rb +0 -0
- data.tar.gz.sig +0 -0
- metadata +101 -97
- metadata.gz.sig +0 -0
- data/test/test_helper.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f586e34e9b14bdbf1876bf3ef5a529796c851ac7
|
4
|
+
data.tar.gz: 26ddeaa6b6ede4f906b6e3373b19530f55fa8836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1df7976f370ea8d7efa29844e5b4e4158ac3c4e72aa11ba2e33f0d17e03d9156288fb3231a801916fae78811edbf89d3ced681e35ee613b6e4f7841357580429
|
7
|
+
data.tar.gz: d333fce2d7a39b241eda7480ab5e382cb18634baa47e1675e7d757eb0615d6d05ede65af02a81b962f2c2f8bff73f550d26588bfd26da0353569ea714293960e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
- jruby
|
7
|
+
|
8
|
+
branches:
|
9
|
+
only:
|
10
|
+
- master
|
11
|
+
before_install:
|
12
|
+
- gem update --system
|
13
|
+
- gem --version
|
14
|
+
|
15
|
+
notifications:
|
16
|
+
email:
|
17
|
+
recipients:
|
18
|
+
- topherreynoso@gmail.com
|
19
|
+
on_failure: change
|
20
|
+
on_success: never
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,12 +3,18 @@
|
|
3
3
|
[![Code Climate](https://codeclimate.com/github/topherreynoso/plangrade-ruby/badges/gpa.svg)](https://codeclimate.com/github/topherreynoso/plangrade-ruby)
|
4
4
|
|
5
5
|
Ruby wrapper for the plangrade API.
|
6
|
-
|
6
|
+
|
7
|
+
Supports OAuth 2.0 authentication, including `refresh_token`. Read the [plangrade docs](https://docs.plangrade.com/#authentication) for more details.
|
8
|
+
|
9
|
+
Additionally, this may be used in conjunction with [omniauth-plangrade](https://github.com/topherreynoso/omniauth-plangrade) in order to facilitate authentication and obtaining a valid `access_token` and `refresh_token` pair for use with this gem to access plangrade API endpoints.
|
10
|
+
|
11
|
+
See the [plangrade-ruby-client](https://github.com/topherreynoso/plangrade-ruby-client) example for implementation of both omniauth-plangrade and plangrade-ruby.
|
12
|
+
|
7
13
|
This README provides only a basic overview of how to use this gem. For more information about the API endpoints, look at the [plangrade docs](https://docs.plangrade.com/#authentication).
|
8
14
|
|
9
15
|
## Installing
|
10
16
|
|
11
|
-
Add
|
17
|
+
Add this line to your application's Gemfile:
|
12
18
|
|
13
19
|
gem 'plangrade-ruby'
|
14
20
|
|
@@ -22,87 +28,218 @@ The plangrade API requires authentication for access to certain endpoints. Below
|
|
22
28
|
|
23
29
|
### Register your application
|
24
30
|
|
25
|
-
Setup a plangrade client application at the [plangrade developer site](https://plangrade.com/oauth/applications).
|
31
|
+
Setup a plangrade client application at the [plangrade developer site](https://plangrade.com/oauth/applications).
|
26
32
|
|
27
|
-
|
33
|
+
### Using omniauth-plangrade to obtain an access token
|
28
34
|
|
29
|
-
|
30
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
-
5. Create a new Pull Request
|
35
|
+
You can use [omniauth-plangrade](https://github.com/topherreynoso/omniauth-plangrade) to obtain a valid access token, as demonstrated below.
|
34
36
|
|
37
|
+
```ruby
|
38
|
+
# In your redirect_uri after the user authorized access, just parse the omniauth response
|
39
|
+
auth = request.env["omniauth.auth"]
|
40
|
+
access_token = auth["credentials"]["token"]
|
41
|
+
refresh_token = auth["credentials"]["refresh_token"]
|
42
|
+
```
|
35
43
|
|
44
|
+
### Using plangrade-ruby OAuth2 Client to obtain an access token
|
36
45
|
|
37
|
-
|
38
|
-
Supports the OAuth 2.0 server-side and client-side flows. Read the plangrade docs for more details: [docs.plangrade.com](https://docs.plangrade.com/#authentication). Additionally, this may be used in conjunction with [plangrade-ruby](https://github.com/topherreynoso/plangrade-ruby) in order to refresh tokens and access plangrade API endpoints.
|
46
|
+
This gem comes bundled with an OAuth2 wrapper that provides convenience methods for getting through the OAuth2 flow.
|
39
47
|
|
40
|
-
|
48
|
+
```ruby
|
49
|
+
# Be sure to require plangrade in any controller where you utilize plangrade-ruby
|
50
|
+
require 'plangrade'
|
41
51
|
|
42
|
-
|
52
|
+
# Begin by getting the authorization url
|
53
|
+
plangrade_client = Plangrade::OAuth2Client.new(ENV['PLANGRADE_CLIENT_ID'], ENV['PLANGRADE_CLIENT_SECRET'])
|
54
|
+
auth_url = plangrade_client.webserver_authorization_url(:redirect_uri => 'your_redirect_uri')
|
55
|
+
```
|
43
56
|
|
44
|
-
|
57
|
+
After the user follows the link created above and authorizes your app, they will be redirected to your `redirect_uri`, with a code in the params that you can use to obtain an access token.
|
45
58
|
|
46
|
-
|
59
|
+
```ruby
|
60
|
+
plangrade_client = Plangrade::OAuth2Client.new(ENV['PLANGRADE_CLIENT_ID'], ENV['PLANGRADE_CLIENT_SECRET'])
|
61
|
+
response = plangrade_client.exchange_auth_code_for_token({:params => {:code => params[:code], :redirect_uri => 'your_redirect_uri'}})
|
62
|
+
token = JSON.parse response.body
|
63
|
+
access_token = token["access_token"]
|
64
|
+
refresh_token = token["refresh_token"]
|
65
|
+
```
|
47
66
|
|
48
|
-
|
67
|
+
You may want to store the `access_token` since it is good for two hours. You may also want to store the `refresh_token` since it can be used to get a new `access_token` at any time, so long as the user does not revoke your app's authorization.
|
68
|
+
|
69
|
+
### Using a stored `refresh_token` to obtain an access token
|
70
|
+
|
71
|
+
This gem also allows you to use a `refresh_token` to obtain a new `access_token`.
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# Set up a plangrade OAuth2 client and retrieve your refresh_token
|
75
|
+
plangrade_client = Plangrade::OAuth2Client.new(ENV['PLANGRADE_CLIENT_ID'], ENV['PLANGRADE_CLIENT_SECRET'])
|
76
|
+
response = plangrade_client.refresh_access_token({:params => {:refresh_token => 'your_refresh_token'}})
|
77
|
+
token = JSON.parse response.body
|
78
|
+
access_token = token["access_token"]
|
79
|
+
refresh_token = token["refresh_token"]
|
80
|
+
```
|
81
|
+
|
82
|
+
### Using plangrade API client to access REST endpoints
|
83
|
+
|
84
|
+
You can view the current state of the client using the `Plangrade#options` method.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
require 'plangrade'
|
88
|
+
|
89
|
+
Plangrade.options
|
90
|
+
#> {:site_url=>"https://plangrade.com", :client_id=>your_client_id, :client_secret=>your_client_secret, :access_token=>current_access_token, :http_adapter=>Plangrade::Connection, :connection_options=>{:max_redirect=>5, :use_ssl=>true}}
|
91
|
+
```
|
92
|
+
|
93
|
+
To change the configuration parameters use the `configure` method. If you set your client_id and client_secret as `ENV['PLANGRADE_CLIENT_ID']` and `ENV['PLANGRADE_CLIENT_SECRET']` then this will automatically be set for you.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
Plangrade.configure do |p|
|
97
|
+
p.client_id = your_client_id
|
98
|
+
p.client_secret = your_client_secret
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
At this point the `access_token` is nil. This will need to be set and, in the next section, we will see how to do this.
|
49
103
|
|
50
104
|
## Usage
|
51
105
|
|
52
|
-
|
106
|
+
This gem offers two way to interact with plangrade's API:
|
107
|
+
|
108
|
+
1. Calling methods on `Plangrade` module.
|
109
|
+
2. Calling methods on an instance of `Plangrade::Client`.
|
53
110
|
|
54
|
-
|
111
|
+
### Calling methods on the plangrade module
|
112
|
+
|
113
|
+
In order for this to work, you will need to set up your `access_token`. This assumes that you already configured the client with your default options as was described above.
|
55
114
|
|
56
115
|
```ruby
|
57
|
-
|
58
|
-
|
116
|
+
# Set up your access_token
|
117
|
+
Plangrade.configure do |p|
|
118
|
+
p.access_token = your_access_token
|
59
119
|
end
|
120
|
+
|
121
|
+
# Get the current user
|
122
|
+
Plangrade.current_user
|
60
123
|
```
|
61
124
|
|
62
|
-
|
125
|
+
### Calling methods on an instance of Plangrade::Client
|
126
|
+
|
127
|
+
**Note:** Use this if you wish to create multiple client instances with different `client_id`, `client_secret`, and/or `access_token`. If your application uses a single pair of `client_id` and `client_secret` credentials, you ONLY need to specify the `access_token`.
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
# Create a client instance using the access_token
|
131
|
+
plangrade = Plangrade::Client.new(:access_token => your_access_token)
|
132
|
+
```
|
63
133
|
|
64
|
-
|
134
|
+
Call methods on the instance.
|
65
135
|
|
66
|
-
|
136
|
+
**User**
|
137
|
+
|
138
|
+
Current user info
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
user = plangrade.current_user
|
142
|
+
user_name = user[:name]
|
143
|
+
```
|
144
|
+
|
145
|
+
Create new user
|
67
146
|
|
68
147
|
```ruby
|
69
|
-
|
70
|
-
:provider => 'plangrade',
|
71
|
-
:uid => '1234567',
|
72
|
-
:info => {
|
73
|
-
:name => 'Compliance Man',
|
74
|
-
:email => 'compliance@plangrade.com',
|
75
|
-
},
|
76
|
-
:credentials => {
|
77
|
-
:token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
|
78
|
-
:refresh_token => 'ABCDEF...', #OAuth 2.0 refresh_token, which you may wish to store
|
79
|
-
:expires_at => 1321747205, # when the access token expires (it always will)
|
80
|
-
:expires => true # this will always be true
|
81
|
-
},
|
82
|
-
:extra => {
|
83
|
-
:raw_info => {
|
84
|
-
:id => '1234567',
|
85
|
-
:name => 'Compliance Man',
|
86
|
-
:email => 'compliance@plangrade.com',
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}
|
148
|
+
new_user_id = plangrade.create_user(params)
|
90
149
|
```
|
91
150
|
|
92
|
-
|
151
|
+
Update user
|
93
152
|
|
94
|
-
|
153
|
+
```ruby
|
154
|
+
updated_user = plangrade.update_user(id, params)
|
155
|
+
```
|
156
|
+
|
157
|
+
Delete user
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
plangrade.delete_user(id)
|
161
|
+
```
|
162
|
+
|
163
|
+
**Companies**
|
164
|
+
|
165
|
+
Create new company
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
new_company_id = plangrade.create_company(params)
|
169
|
+
```
|
170
|
+
|
171
|
+
Get company info
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
company = plangrade.get_company(id)
|
175
|
+
```
|
176
|
+
|
177
|
+
Get all of a user's companies
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
companies = plangrade.all_companies
|
181
|
+
```
|
182
|
+
|
183
|
+
Update company
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
updated_company = plangrade.update_company(id, params)
|
187
|
+
```
|
188
|
+
|
189
|
+
Delete company
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
plangrade.delete_company(id)
|
193
|
+
```
|
194
|
+
|
195
|
+
**Participants**
|
196
|
+
|
197
|
+
Create new participant
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
new_participant_id = plangrade.create_participant(params)
|
201
|
+
```
|
202
|
+
|
203
|
+
Get participant info
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
participant = plangrade.get_participant(id)
|
207
|
+
```
|
208
|
+
|
209
|
+
Get all of a company's participants
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
participants = plangrade.all_participants(:company_id => id, params)
|
213
|
+
```
|
214
|
+
|
215
|
+
Update participant info
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
updated_participant = plangrade.update_participant(id, params)
|
219
|
+
```
|
220
|
+
|
221
|
+
Archive participant
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
archived_participant_id = plangrade.archive_participant(id)
|
225
|
+
```
|
226
|
+
|
227
|
+
Delete participant
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
plangrade.delete_participant(id)
|
231
|
+
```
|
95
232
|
|
96
|
-
|
233
|
+
## Supported Ruby Versions
|
97
234
|
|
98
|
-
|
99
|
-
2. extract the authorization code contained in it,
|
100
|
-
3. and hit plangrade and obtain an access token which will get placed in the `request.env['omniauth.auth']['credentials']` hash.
|
235
|
+
This library aims to support and is [tested against](https://travis-ci.org/topherreynoso/plangrade-ruby) the following Ruby versions:
|
101
236
|
|
102
|
-
|
237
|
+
1. Ruby 1.9.3
|
238
|
+
2. Ruby 2.0.0
|
239
|
+
3. Ruby 2.1.0
|
240
|
+
4. jruby
|
103
241
|
|
104
|
-
|
105
|
-
The refresh_token, however, has no expiration and may be used until a user revokes your app's access.
|
242
|
+
This library may inadvertently work (or seem to work) on other Ruby implementations, however, support will only be provided for the versions listed above.
|
106
243
|
|
107
244
|
## License
|
108
245
|
|
data/Rakefile
CHANGED
@@ -6,19 +6,19 @@ module Plangrade
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def update_company(id, opts={})
|
9
|
-
put("/api/v1/companies/#{id}", opts)
|
9
|
+
put("/api/v1/companies/#{id}", opts)
|
10
10
|
end
|
11
11
|
|
12
12
|
def delete_company(id)
|
13
|
-
delete("/api/v1/companies/#{id}"
|
13
|
+
delete("/api/v1/companies/#{id}")
|
14
14
|
end
|
15
15
|
|
16
16
|
def get_company(id)
|
17
|
-
get("/api/v1/companies/#{id}")
|
17
|
+
get("/api/v1/companies/#{id}")
|
18
18
|
end
|
19
19
|
|
20
20
|
def all_companies(opts={})
|
21
|
-
get("/api/v1/companies", opts)
|
21
|
+
get("/api/v1/companies", opts)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -6,23 +6,24 @@ module Plangrade
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def update_participant(id, opts={})
|
9
|
-
put("/api/v1/participants/#{id}", opts)
|
9
|
+
put("/api/v1/participants/#{id}", opts)
|
10
10
|
end
|
11
11
|
|
12
12
|
def delete_participant(id)
|
13
|
-
delete("/api/v1/participants/#{id}"
|
13
|
+
delete("/api/v1/participants/#{id}")
|
14
14
|
end
|
15
15
|
|
16
16
|
def archive_participant(id)
|
17
|
-
get("api/v1/participants/archive?participant_id=#{id}")
|
17
|
+
get("/api/v1/participants/archive?participant_id=#{id}")
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_participant(id)
|
21
|
-
get("/api/v1/participants/#{id}")
|
21
|
+
get("/api/v1/participants/#{id}")
|
22
22
|
end
|
23
23
|
|
24
24
|
def all_participants(opts={})
|
25
|
-
|
25
|
+
company_id = opts[:company_id]
|
26
|
+
get("/api/v1/participants?company_id=#{company_id}")
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
data/lib/plangrade/api/user.rb
CHANGED
@@ -6,15 +6,15 @@ module Plangrade
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def update_user(id, opts={})
|
9
|
-
put("/api/v1/users/#{id}", opts)
|
9
|
+
put("/api/v1/users/#{id}", opts)
|
10
10
|
end
|
11
11
|
|
12
12
|
def delete_user(id)
|
13
|
-
delete("/api/v1/users/#{id}"
|
13
|
+
delete("/api/v1/users/#{id}")
|
14
14
|
end
|
15
15
|
|
16
16
|
def current_user
|
17
|
-
get('/api/v1/me')
|
17
|
+
get('/api/v1/me')
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Plangrade
|
2
2
|
module Resources
|
3
|
-
class
|
3
|
+
class Participant < Plangrade::Resources::Base
|
4
4
|
|
5
5
|
def self.create(company_id, first_name, last_name, street1, street2, city, state, zip, dob, ssn, email, phone, employee_id)
|
6
6
|
|
@@ -13,7 +13,7 @@ module Plangrade
|
|
13
13
|
new(:id => id)
|
14
14
|
end
|
15
15
|
|
16
|
-
attr_accessor_deffered :
|
16
|
+
attr_accessor_deffered :company_id, :employee_id, :first_name, :last_name, :street1, :street2, :city, :state, :zip,
|
17
17
|
:dob, :ssn, :email, :phone
|
18
18
|
|
19
19
|
def update!(params)
|
@@ -2,8 +2,8 @@ module Plangrade
|
|
2
2
|
module Resources
|
3
3
|
class User < Plangrade::Resources::Base
|
4
4
|
|
5
|
-
def self.
|
6
|
-
result = api_handler.
|
5
|
+
def self.current_user
|
6
|
+
result = api_handler.current_user
|
7
7
|
return nil unless result.success?
|
8
8
|
new(result.body)
|
9
9
|
end
|
@@ -15,7 +15,7 @@ module Plangrade
|
|
15
15
|
new(:id => id)
|
16
16
|
end
|
17
17
|
|
18
|
-
attr_accessor_deffered :
|
18
|
+
attr_accessor_deffered :email, :name
|
19
19
|
|
20
20
|
def update!(params)
|
21
21
|
api_handler.update_user(@id, params)
|
data/plangrade-ruby.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = %q{plangrade API client}
|
12
12
|
spec.description = %q{A ruby wrapper for accessing plangrade's REST API}
|
13
13
|
spec.homepage = "https://github.com/topherreynoso/plangrade-ruby"
|
14
|
-
spec.
|
14
|
+
spec.licenses = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -21,19 +21,15 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.cert_chain = ['certs/public.pem']
|
22
22
|
spec.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "minitest"
|
27
|
-
spec.add_development_dependency "vcr"
|
28
|
-
spec.add_development_dependency "webmock"
|
29
|
-
|
30
|
-
spec.add_dependency "faraday"
|
31
|
-
spec.add_dependency "json"
|
32
24
|
spec.add_dependency 'oj', '~> 2.0'
|
33
25
|
spec.add_dependency 'multi_json', '~> 1.8'
|
34
26
|
spec.add_dependency 'rest-client', '~> 1.6'
|
35
27
|
spec.add_dependency 'addressable', '~> 2.3'
|
36
28
|
spec.add_dependency 'oauth2-client', '~> 2.0'
|
37
29
|
|
38
|
-
spec.
|
30
|
+
spec.add_development_dependency 'rake'
|
31
|
+
spec.add_development_dependency 'rspec'
|
32
|
+
spec.add_development_dependency 'simplecov', '>= 0.8'
|
33
|
+
spec.add_development_dependency 'webmock', '>= 1.9'
|
34
|
+
spec.add_development_dependency 'yard', '>= 0.8'
|
39
35
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
21
|
+
require 'ostruct'
|
22
|
+
|
23
|
+
describe Plangrade::Api::Company do
|
24
|
+
|
25
|
+
before :all do
|
26
|
+
@client = Plangrade::Client.new(
|
27
|
+
:site_url => 'https://plangrade.com',
|
28
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
29
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
30
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
subject { @client }
|
35
|
+
|
36
|
+
describe 'create_company' do
|
37
|
+
it 'makes an http request' do
|
38
|
+
params = {:name => 'plangrade, llc', :ein => '123456789'}
|
39
|
+
@client.should_receive(:post).with('/api/v1/companies', params)
|
40
|
+
@client.create_company(params)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'update_company' do
|
45
|
+
it 'makes an http request' do
|
46
|
+
params = {:name => 'plangrade, inc'}
|
47
|
+
@client.should_receive(:put).with('/api/v1/companies/1', params)
|
48
|
+
@client.update_company(1, params)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'delete_company' do
|
53
|
+
it 'makes an http request' do
|
54
|
+
@client.should_receive(:delete).with('/api/v1/companies/1')
|
55
|
+
@client.delete_company(1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'get_company' do
|
60
|
+
it 'makes an http request' do
|
61
|
+
@client.should_receive(:get).with('/api/v1/companies/1')
|
62
|
+
@client.get_company(1)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'all_companies' do
|
67
|
+
it 'makes an http request' do
|
68
|
+
@client.should_receive(:get).with('/api/v1/companies', {:page => 1, :letter => 'm'})
|
69
|
+
@client.all_companies({:page => 1, :letter => 'm'})
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|