proz 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ed793d72687e277deb02dbf64b4e873ac7e88be
4
- data.tar.gz: 86ba561b9085583f1abee5722d86f8eef7c6b370
3
+ metadata.gz: 17ebaa46f749ca43d271be89e94c6cd76d460317
4
+ data.tar.gz: 2df566c85c7b2edc8583d22885b10c4d91799a8d
5
5
  SHA512:
6
- metadata.gz: 9c87e3088e2807a0bc6c85755fc11911ef27ea1a53ff9212c04514008327b0eb131668f10d89a9ca4a493d04b4bdf10a2a41bb7daaea4cac3fa2ac715c9b2ca2
7
- data.tar.gz: a9487d9fba83d3855ce2de8b17292f9626410a75b0543aac61c7a1447b03a0de154da374fa524db1e670886d1b795015158241b98422ae2ed089e953b3cea85c
6
+ metadata.gz: 842518c039c3c15cc95641102305ddd14b122db648f5966e2bf16fcde045d96a2a9254b1958a8852eb37ffa6b6e7a501c68cc0e550e71b2d8689fb85f8d0a71f
7
+ data.tar.gz: 20e25a4fd5ec07c6821a317d40ad25fd2b1822428bc519d0b89815bc59a24b9affff3fb7c2020b405daf590c315a14bd664bebef483052a9615763552f628a7e
@@ -11,11 +11,32 @@ module Proz
11
11
  end
12
12
 
13
13
  def freelancer
14
- @freelancer ||= self.class.get("/freelancer/#{uuid}", headers: { 'X-Proz-API-Key' => key})['data']
14
+ case
15
+ when freelancer_response.has_key?('error')
16
+ if freelancer_response['error'].eql?('invalid_api_key')
17
+ raise 'Invalid API Key'
18
+ else
19
+ raise 'Invalid Request'
20
+ end
21
+ when freelancer_response.has_key?('error_messages')
22
+ if freelancer_response['error_messages'][0].eql?('No freelancer was found with that UUID.')
23
+ raise 'No freelancer was found with that UUID'
24
+ else
25
+ raise 'Invalid Request'
26
+ end
27
+ else
28
+ freelancer_response['data']
29
+ end
15
30
  end
16
31
 
17
32
  def method_missing(name, *args, &block)
18
33
  freelancer.has_key?(name.to_s) ? freelancer[name.to_s] : super
19
34
  end
35
+
36
+ private
37
+
38
+ def freelancer_response
39
+ @freelancer_response ||= self.class.get("/freelancer/#{uuid}", headers: { 'X-Proz-API-Key' => key})
40
+ end
20
41
  end
21
42
  end
@@ -12,8 +12,29 @@ module Proz
12
12
  end
13
13
 
14
14
  def freelancer_matches
15
+ case
16
+ when freelancer_matches_response.has_key?('error')
17
+ if freelancer_matches_response['error'].eql?('invalid_api_key')
18
+ raise 'Invalid API Key'
19
+ else
20
+ raise 'Invalid Request'
21
+ end
22
+ when freelancer_matches_response.has_key?('meta')
23
+ if freelancer_matches_response['meta']['num_results'].eql?(0)
24
+ {}
25
+ else
26
+ freelancer_matches_response['data']
27
+ end
28
+ else
29
+ freelancer_matches_response['data']
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def freelancer_matches_response
15
36
  all_options = language_pair.merge!(options)
16
- self.class.get("/freelancer-matches", query: all_options, headers: { 'X-Proz-API-Key' => key})['data']
37
+ @freelancer_matches_response ||= self.class.get("/freelancer-matches", query: all_options, headers: { 'X-Proz-API-Key' => key})
17
38
  end
18
39
  end
19
40
  end
data/lib/proz/oauth.rb CHANGED
@@ -16,7 +16,15 @@ module Proz
16
16
  end
17
17
 
18
18
  def exchange_code_for_token(code)
19
- @token ||= self.class.post('https://www.proz.com/oauth/token', :body => { :code => code, :redirect_uri => redirect_uri, :client_id => client_id, :scope => '', :client_secret => client_secret, :grant_type => 'authorization_code' })
19
+ if token(code).has_key?('error')
20
+ if token(code)['error'].eql?('invalid_grant')
21
+ raise "Authorization code doesn't exist or is invalid for the client"
22
+ else
23
+ raise 'Invalid Request'
24
+ end
25
+ else
26
+ token(code)
27
+ end
20
28
  end
21
29
 
22
30
  def request_new_token_with_refresh_token(refresh_token)
@@ -25,8 +33,12 @@ module Proz
25
33
 
26
34
  private
27
35
 
36
+ def token(code)
37
+ @token ||= self.class.post('https://www.proz.com/oauth/token', :body => { :code => code, :redirect_uri => redirect_uri, :client_id => client_id, :scope => '', :client_secret => client_secret, :grant_type => 'authorization_code' })
38
+ end
39
+
28
40
  def client
29
41
  @client ||= OAuth2::Client.new(client_id, client_secret, :site => 'https://www.proz.com')
30
42
  end
31
43
  end
32
- end
44
+ end
data/lib/proz/profile.rb CHANGED
@@ -10,11 +10,28 @@ module Proz
10
10
  end
11
11
 
12
12
  def profile
13
- @profile ||= self.class.get("/freelancer/me", headers: { 'Authorization' => "Bearer #{token}" })['data']
13
+ case
14
+ when profile_response.has_key?('error')
15
+ if profile_response['error'].eql?('invalid_token')
16
+ raise 'Invalid Token'
17
+ elsif profile_response['error'].eql?('expired_token')
18
+ raise 'Access Token Expired'
19
+ else
20
+ raise 'Invalid Request'
21
+ end
22
+ else
23
+ profile_response['data']
24
+ end
14
25
  end
15
26
 
16
27
  def method_missing(name, *args, &block)
17
28
  profile.has_key?(name.to_s) ? profile[name.to_s] : super
18
29
  end
30
+
31
+ private
32
+
33
+ def profile_response
34
+ @profile ||= self.class.get("/freelancer/me", headers: { 'Authorization' => "Bearer #{token}" })
35
+ end
19
36
  end
20
- end
37
+ end
data/lib/proz/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Proz
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.proz.com/oauth/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: code=xf505e6ac620cb51bb8dc99d4bddbef2f3122e70&redirect_uri=http%3A%2F%2Fwww.example.com&client_id=xxxxxxxxx&scope=&client_secret=yyyyyyyyy&grant_type=authorization_code
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 400
19
+ message: Bad Request
20
+ headers:
21
+ Date:
22
+ - Wed, 04 Feb 2015 08:27:48 GMT
23
+ Server:
24
+ - Apache
25
+ Set-Cookie:
26
+ - PHPSESSID=78683f88050679d8f1a0b981396b749c; expires=Fri, 03-Feb-2017 08:27:48
27
+ GMT; path=/; domain=.proz.com
28
+ Expires:
29
+ - Thu, 19 Nov 1981 08:52:00 GMT
30
+ Cache-Control:
31
+ - no-store
32
+ Pragma:
33
+ - no-cache
34
+ Vary:
35
+ - Accept-Encoding
36
+ Content-Length:
37
+ - '107'
38
+ Connection:
39
+ - close
40
+ Content-Type:
41
+ - application/json
42
+ body:
43
+ encoding: UTF-8
44
+ string: '{"error":"invalid_grant","error_description":"Authorization code doesn''t
45
+ exist or is invalid for the client"}'
46
+ http_version:
47
+ recorded_at: Wed, 04 Feb 2015 08:28:19 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,33 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.proz.com/v2/freelancer-matches?country_code=us&language_pair=eng_esl&min_yrs_proz=10
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Proz-Api-Key:
11
+ - yyyyyyyyy
12
+ response:
13
+ status:
14
+ code: 401
15
+ message: Unauthorized
16
+ headers:
17
+ Date:
18
+ - Wed, 04 Feb 2015 07:43:47 GMT
19
+ Server:
20
+ - Apache
21
+ Cache-Control:
22
+ - no-store
23
+ Content-Length:
24
+ - '116'
25
+ Content-Type:
26
+ - application/json
27
+ body:
28
+ encoding: UTF-8
29
+ string: '{"error":"invalid_api_key","error_description":"Invalid API key.","error_messages":["Invalid
30
+ API key."],"success":0}'
31
+ http_version:
32
+ recorded_at: Wed, 04 Feb 2015 07:44:18 GMT
33
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,32 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.proz.com/v2/freelancer-matches?country_code=us&language_pair=eng_esl&min_yrs_proz=50
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Proz-Api-Key:
11
+ - xxxxxxxxx
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Date:
18
+ - Wed, 04 Feb 2015 08:12:24 GMT
19
+ Server:
20
+ - Apache
21
+ Cache-Control:
22
+ - no-cache
23
+ Transfer-Encoding:
24
+ - chunked
25
+ Content-Type:
26
+ - application/json
27
+ body:
28
+ encoding: UTF-8
29
+ string: '{"success":1,"meta":{"num_results":0},"data":[]}'
30
+ http_version:
31
+ recorded_at: Wed, 04 Feb 2015 08:12:56 GMT
32
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,33 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.proz.com/v2/freelancer/663e4488-58a1-4713-992c-c6d90aafa3cb
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Proz-Api-Key:
11
+ - yyyyyyyyy
12
+ response:
13
+ status:
14
+ code: 401
15
+ message: Unauthorized
16
+ headers:
17
+ Date:
18
+ - Wed, 04 Feb 2015 06:49:20 GMT
19
+ Server:
20
+ - Apache
21
+ Cache-Control:
22
+ - no-store
23
+ Content-Length:
24
+ - '116'
25
+ Content-Type:
26
+ - application/json
27
+ body:
28
+ encoding: UTF-8
29
+ string: '{"error":"invalid_api_key","error_description":"Invalid API key.","error_messages":["Invalid
30
+ API key."],"success":0}'
31
+ http_version:
32
+ recorded_at: Wed, 04 Feb 2015 06:49:51 GMT
33
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,34 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.proz.com/v2/freelancer/xxxxx
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Proz-Api-Key:
11
+ - xxxxxxxxx
12
+ response:
13
+ status:
14
+ code: 400
15
+ message: Bad Request
16
+ headers:
17
+ Date:
18
+ - Wed, 04 Feb 2015 07:12:07 GMT
19
+ Server:
20
+ - Apache
21
+ Cache-Control:
22
+ - no-cache
23
+ Connection:
24
+ - close
25
+ Transfer-Encoding:
26
+ - chunked
27
+ Content-Type:
28
+ - application/json
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"success":0,"error_messages":["No freelancer was found with that UUID."]}'
32
+ http_version:
33
+ recorded_at: Wed, 04 Feb 2015 07:12:38 GMT
34
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.proz.com/v2/freelancer/me
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - Bearer 4b89e678e8670bca496c9bd80d8b09b87c10d605
12
+ response:
13
+ status:
14
+ code: 401
15
+ message: Unauthorized
16
+ headers:
17
+ Date:
18
+ - Wed, 04 Feb 2015 08:23:11 GMT
19
+ Server:
20
+ - Apache
21
+ Cache-Control:
22
+ - no-store
23
+ Www-Authenticate:
24
+ - Bearer realm="Service", error="expired_token", error_description="The access
25
+ token provided has expired"
26
+ Content-Length:
27
+ - '85'
28
+ Content-Type:
29
+ - application/json
30
+ body:
31
+ encoding: UTF-8
32
+ string: '{"error":"expired_token","error_description":"The access token provided
33
+ has expired"}'
34
+ http_version:
35
+ recorded_at: Wed, 04 Feb 2015 08:23:42 GMT
36
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.proz.com/v2/freelancer/me
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - Bearer q76470e1fb5e5c0347c3a7393f6312fd980096ae
12
+ response:
13
+ status:
14
+ code: 401
15
+ message: Unauthorized
16
+ headers:
17
+ Date:
18
+ - Wed, 04 Feb 2015 08:19:59 GMT
19
+ Server:
20
+ - Apache
21
+ Cache-Control:
22
+ - no-store
23
+ Www-Authenticate:
24
+ - Bearer realm="Service", error="invalid_token", error_description="The access
25
+ token provided is invalid"
26
+ Content-Length:
27
+ - '84'
28
+ Content-Type:
29
+ - application/json
30
+ body:
31
+ encoding: UTF-8
32
+ string: '{"error":"invalid_token","error_description":"The access token provided
33
+ is invalid"}'
34
+ http_version:
35
+ recorded_at: Wed, 04 Feb 2015 08:20:30 GMT
36
+ recorded_with: VCR 2.9.3
@@ -26,4 +26,18 @@ RSpec.describe Proz::FreelancerMatches do
26
26
  expect(fm.freelancer_matches[0]['freelancer']['uuid']).to eq('b9eade6d-33ac-4c7d-b6f1-42905375fc0b')
27
27
  end
28
28
  end
29
+
30
+ it 'returns an error if the key is invalid' do
31
+ VCR.use_cassette 'freelancer_matches_invalid_key' do
32
+ fm = Proz::FreelancerMatches.new(key: 'yyyyyyyyy', language_pair: 'eng_esl', min_yrs_proz: 10, country_code: 'us')
33
+ expect { fm.freelancer_matches }.to raise_error("Invalid API Key")
34
+ end
35
+ end
36
+
37
+ it 'returns an empty hash if the query has no results' do
38
+ VCR.use_cassette 'freelancer_matches_no_results' do
39
+ fm = Proz::FreelancerMatches.new(key: 'xxxxxxxxx', language_pair: 'eng_esl', min_yrs_proz: 50, country_code: 'us')
40
+ expect(fm.freelancer_matches).to eq({})
41
+ end
42
+ end
29
43
  end
@@ -6,6 +6,13 @@ RSpec.describe Proz::Freelancer do
6
6
  expect(Proz::Freelancer.base_uri).to eq('https://api.proz.com/v2')
7
7
  end
8
8
 
9
+ it 'returns an error if the key is invalid' do
10
+ VCR.use_cassette 'invalid_key' do
11
+ freelancer = Proz::Freelancer.new(key: 'yyyyyyyyy', uuid: '663e4488-58a1-4713-992c-c6d90aafa3cb')
12
+ expect { freelancer.freelancer }.to raise_error('Invalid API Key')
13
+ end
14
+ end
15
+
9
16
  it 'returns a freelancer' do
10
17
  VCR.use_cassette 'freelancer' do
11
18
  freelancer = Proz::Freelancer.new(key: 'xxxxxxxxxx', uuid: '663e4488-58a1-4713-992c-c6d90aafa3cb')
@@ -13,6 +20,13 @@ RSpec.describe Proz::Freelancer do
13
20
  end
14
21
  end
15
22
 
23
+ it 'returns an error if the uuid is invalid' do
24
+ VCR.use_cassette 'invalid_uuid' do
25
+ freelancer = Proz::Freelancer.new(key: 'xxxxxxxxx', uuid: 'xxxxx')
26
+ expect { freelancer.site_name }.to raise_error("No freelancer was found with that UUID")
27
+ end
28
+ end
29
+
16
30
  it "returns a freelancer's uuid" do
17
31
  VCR.use_cassette 'freelancer' do
18
32
  freelancer = Proz::Freelancer.new(key: 'xxxxxxxxxx', uuid: '663e4488-58a1-4713-992c-c6d90aafa3cb')
@@ -37,4 +37,11 @@ RSpec.describe Proz::OAuth do
37
37
  expect(proz.request_new_token_with_refresh_token('x92701ac20cb02a5742f2a0288b7a9f6a6d0b265')['refresh_token']).to eq('x6ee311617f0f0520e99de13b07ee61c03777134')
38
38
  end
39
39
  end
40
+
41
+ it 'requests an error if the code is invalid' do
42
+ VCR.use_cassette 'exchange_code_for_token_invalid_code' do
43
+ proz = Proz::OAuth.new(client_id: 'xxxxxxxxx', client_secret: 'yyyyyyyyy', redirect_uri: 'http://www.example.com')
44
+ expect { proz.exchange_code_for_token('xf505e6ac620cb51bb8dc99d4bddbef2f3122e70') }.to raise_error("Authorization code doesn't exist or is invalid for the client")
45
+ end
46
+ end
40
47
  end
@@ -29,4 +29,18 @@ RSpec.describe Proz::Profile do
29
29
  expect(profile.profile_url).to eq('http://www.proz.com/profile/1979687')
30
30
  end
31
31
  end
32
+
33
+ it 'should return an error is the access token is invalid' do
34
+ VCR.use_cassette 'profile_query_invalid_access_token' do
35
+ profile = Proz::Profile.new(token: 'q76470e1fb5e5c0347c3a7393f6312fd980096ae')
36
+ expect { profile.profile_url }.to raise_error('Invalid Token')
37
+ end
38
+ end
39
+
40
+ it 'should return an error is the access token is expired' do
41
+ VCR.use_cassette 'profile_query_access_token_expired' do
42
+ profile = Proz::Profile.new(token: '4b89e678e8670bca496c9bd80d8b09b87c10d605')
43
+ expect { profile.profile_url }.to raise_error('Access Token Expired')
44
+ end
45
+ end
32
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin S. Dias
@@ -131,10 +131,17 @@ files:
131
131
  - lib/proz/version.rb
132
132
  - proz.gemspec
133
133
  - spec/fixtures/vcr_cassettes/exchange_code_for_token.yml
134
+ - spec/fixtures/vcr_cassettes/exchange_code_for_token_invalid_code.yml
134
135
  - spec/fixtures/vcr_cassettes/freelancer.yml
136
+ - spec/fixtures/vcr_cassettes/freelancer_matches_invalid_key.yml
137
+ - spec/fixtures/vcr_cassettes/freelancer_matches_no_results.yml
138
+ - spec/fixtures/vcr_cassettes/invalid_key.yml
139
+ - spec/fixtures/vcr_cassettes/invalid_uuid.yml
135
140
  - spec/fixtures/vcr_cassettes/match_query.yml
136
141
  - spec/fixtures/vcr_cassettes/match_query_options.yml
137
142
  - spec/fixtures/vcr_cassettes/profile_query.yml
143
+ - spec/fixtures/vcr_cassettes/profile_query_access_token_expired.yml
144
+ - spec/fixtures/vcr_cassettes/profile_query_invalid_access_token.yml
138
145
  - spec/fixtures/vcr_cassettes/refresh_token.yml
139
146
  - spec/proz/freelancer_matches_spec.rb
140
147
  - spec/proz/freelancer_spec.rb
@@ -167,10 +174,17 @@ specification_version: 4
167
174
  summary: Ruby wrapper for the ProZ.com API
168
175
  test_files:
169
176
  - spec/fixtures/vcr_cassettes/exchange_code_for_token.yml
177
+ - spec/fixtures/vcr_cassettes/exchange_code_for_token_invalid_code.yml
170
178
  - spec/fixtures/vcr_cassettes/freelancer.yml
179
+ - spec/fixtures/vcr_cassettes/freelancer_matches_invalid_key.yml
180
+ - spec/fixtures/vcr_cassettes/freelancer_matches_no_results.yml
181
+ - spec/fixtures/vcr_cassettes/invalid_key.yml
182
+ - spec/fixtures/vcr_cassettes/invalid_uuid.yml
171
183
  - spec/fixtures/vcr_cassettes/match_query.yml
172
184
  - spec/fixtures/vcr_cassettes/match_query_options.yml
173
185
  - spec/fixtures/vcr_cassettes/profile_query.yml
186
+ - spec/fixtures/vcr_cassettes/profile_query_access_token_expired.yml
187
+ - spec/fixtures/vcr_cassettes/profile_query_invalid_access_token.yml
174
188
  - spec/fixtures/vcr_cassettes/refresh_token.yml
175
189
  - spec/proz/freelancer_matches_spec.rb
176
190
  - spec/proz/freelancer_spec.rb