proz 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Proz::OAuth do
4
+
5
+ it 'sets the client_id' do
6
+ oauth2 = Proz::OAuth.new(client_id: 'abcdef', client_secret: 'xyz123', redirect_uri: 'https://www.example.com')
7
+ expect(oauth2.client_id).to eq('abcdef')
8
+ end
9
+
10
+ it 'sets the client_secret' do
11
+ oauth2 = Proz::OAuth.new(client_id: 'abcdef', client_secret: 'xyz123', redirect_uri: 'https://www.example.com')
12
+ expect(oauth2.client_secret).to eq('xyz123')
13
+ end
14
+
15
+ it 'sets the redirect_uri' do
16
+ oauth2 = Proz::OAuth.new(client_id: 'abcdef', client_secret: 'xyz123', redirect_uri: 'https://www.example.com')
17
+ expect(oauth2.redirect_uri).to eq('https://www.example.com')
18
+ end
19
+
20
+ it 'returns a link for the user to authorize the app' do
21
+ proz = Proz::OAuth.new(client_id: 'abc123xxxxxxxxxxxxxx', client_secret: 'abc123xxxxyyyyy', redirect_uri: 'http://www.example.com')
22
+ expect(proz.link).to eq("https://www.proz.com/oauth/authorize?client_id=abc123xxxxxxxxxxxxxx&redirect_uri=http%3A%2F%2Fwww.example.com&response_type=code&scope=proz")
23
+ end
24
+
25
+ it 'exchanges a code for an access token' do
26
+ VCR.use_cassette 'exchange_code_for_token' do
27
+ proz = Proz::OAuth.new(client_id: 'xxxxxxxxx', client_secret: 'yyyyyyyyy', redirect_uri: 'http://www.example.com')
28
+ expect(proz.exchange_code_for_token('xf505e6ac620cb51bb8dc99d4bddbef2f3122e70')['access_token']).to eq('q0245b8b893717386310160f117d1720583f3d22')
29
+ expect(proz.exchange_code_for_token('xf505e6ac620cb51bb8dc99d4bddbef2f3122e70')['refresh_token']).to eq('g197d8ba9dd0c608ee6e2c83c3b363540ec14b31')
30
+ end
31
+ end
32
+
33
+ it 'requests a new token with the refresh token' do
34
+ VCR.use_cassette 'refresh_token' do
35
+ proz = Proz::OAuth.new(client_id: 'xxxxxxxxx', client_secret: 'yyyyyyyyy', redirect_uri: 'http://www.example.com')
36
+ expect(proz.request_new_token_with_refresh_token('x92701ac20cb02a5742f2a0288b7a9f6a6d0b265')['access_token']).to eq('x325fa5d0a661df967a6c52d07ba352649a7c153')
37
+ expect(proz.request_new_token_with_refresh_token('x92701ac20cb02a5742f2a0288b7a9f6a6d0b265')['refresh_token']).to eq('x6ee311617f0f0520e99de13b07ee61c03777134')
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Proz::Profile do
4
+
5
+ it 'should return the full profile of a user given an access token' do
6
+ VCR.use_cassette 'profile_query' do
7
+ profile = Proz::Profile.new(token: 'q76470e1fb5e5c0347c3a7393f6312fd980096ae')
8
+ expect(profile.profile).to eq({"uuid"=>"7bbfdd74-a2a4-484f-8dbc-215a67026ce1", "site_name"=>"Kevin Dias", "profile_url"=>"http://www.proz.com/profile/1979687", "contact_info"=>{"first_name"=>"Kevin", "middle_name"=>nil, "last_name"=>"Dias"}, "skills"=>{"language_pairs"=>[], "general_disciplines"=>[{"disc_gen_id"=>1, "disc_gen_name"=>"Tech/Engineering"}, {"disc_gen_id"=>2, "disc_gen_name"=>"Art/Literary"}, {"disc_gen_id"=>3, "disc_gen_name"=>"Medical"}, {"disc_gen_id"=>4, "disc_gen_name"=>"Law/Patents"}, {"disc_gen_id"=>5, "disc_gen_name"=>"Science"}, {"disc_gen_id"=>6, "disc_gen_name"=>"Bus/Financial"}, {"disc_gen_id"=>7, "disc_gen_name"=>"Marketing"}, {"disc_gen_id"=>8, "disc_gen_name"=>"Other"}, {"disc_gen_id"=>9, "disc_gen_name"=>"Social Sciences"}], "specific_disciplines"=>[]}})
9
+ end
10
+ end
11
+
12
+ it 'should return the uuid of a user given an access token' do
13
+ VCR.use_cassette 'profile_query' do
14
+ profile = Proz::Profile.new(token: 'q76470e1fb5e5c0347c3a7393f6312fd980096ae')
15
+ expect(profile.uuid).to eq('7bbfdd74-a2a4-484f-8dbc-215a67026ce1')
16
+ end
17
+ end
18
+
19
+ it 'should return the site_name of a user given an access token' do
20
+ VCR.use_cassette 'profile_query' do
21
+ profile = Proz::Profile.new(token: 'q76470e1fb5e5c0347c3a7393f6312fd980096ae')
22
+ expect(profile.site_name).to eq('Kevin Dias')
23
+ end
24
+ end
25
+
26
+ it 'should return the profile_url of a user given an access token' do
27
+ VCR.use_cassette 'profile_query' do
28
+ profile = Proz::Profile.new(token: 'q76470e1fb5e5c0347c3a7393f6312fd980096ae')
29
+ expect(profile.profile_url).to eq('http://www.proz.com/profile/1979687')
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,7 @@
1
- require 'codeclimate-test-reporter'
2
- CodeClimate::TestReporter.start
3
1
  require 'proz'
2
+ require 'webmock/rspec'
3
+ require 'vcr'
4
+ VCR.configure do |config|
5
+ config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
6
+ config.hook_into :webmock
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin S. Dias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: vcr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: httparty
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: oauth2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  description: A Ruby wrapper for working with the ProZ.com 2.0 API, a REST-like API
56
98
  for interacting with ProZ.com services.
57
99
  email:
@@ -62,15 +104,28 @@ extra_rdoc_files: []
62
104
  files:
63
105
  - ".gitignore"
64
106
  - ".rspec"
107
+ - ".travis.yml"
65
108
  - Gemfile
66
109
  - LICENSE.txt
67
110
  - README.md
68
111
  - Rakefile
69
112
  - lib/proz.rb
70
- - lib/proz/client.rb
113
+ - lib/proz/freelancer.rb
114
+ - lib/proz/freelancer_matches.rb
115
+ - lib/proz/oauth.rb
116
+ - lib/proz/profile.rb
71
117
  - lib/proz/version.rb
72
118
  - proz.gemspec
73
- - spec/proz_spec.rb
119
+ - spec/fixtures/vcr_cassettes/exchange_code_for_token.yml
120
+ - spec/fixtures/vcr_cassettes/freelancer.yml
121
+ - spec/fixtures/vcr_cassettes/match_query.yml
122
+ - spec/fixtures/vcr_cassettes/match_query_options.yml
123
+ - spec/fixtures/vcr_cassettes/profile_query.yml
124
+ - spec/fixtures/vcr_cassettes/refresh_token.yml
125
+ - spec/proz/freelancer_matches_spec.rb
126
+ - spec/proz/freelancer_spec.rb
127
+ - spec/proz/oauth_spec.rb
128
+ - spec/proz/profile_spec.rb
74
129
  - spec/spec_helper.rb
75
130
  homepage: ''
76
131
  licenses:
@@ -97,5 +152,14 @@ signing_key:
97
152
  specification_version: 4
98
153
  summary: Ruby wrapper for the ProZ.com API
99
154
  test_files:
100
- - spec/proz_spec.rb
155
+ - spec/fixtures/vcr_cassettes/exchange_code_for_token.yml
156
+ - spec/fixtures/vcr_cassettes/freelancer.yml
157
+ - spec/fixtures/vcr_cassettes/match_query.yml
158
+ - spec/fixtures/vcr_cassettes/match_query_options.yml
159
+ - spec/fixtures/vcr_cassettes/profile_query.yml
160
+ - spec/fixtures/vcr_cassettes/refresh_token.yml
161
+ - spec/proz/freelancer_matches_spec.rb
162
+ - spec/proz/freelancer_spec.rb
163
+ - spec/proz/oauth_spec.rb
164
+ - spec/proz/profile_spec.rb
101
165
  - spec/spec_helper.rb
@@ -1,23 +0,0 @@
1
- require 'httparty'
2
-
3
- FREELANCER_URL = "/freelancer/"
4
-
5
- module Proz
6
- class Client
7
- include HTTParty
8
- base_uri "https://api.proz.com/v2"
9
- attr_reader :key
10
- def initialize(key:)
11
- @key = key
12
- end
13
-
14
- def freelancer(uuid)
15
- self.class.get("/freelancer/#{uuid}", headers: { 'X-Proz-API-Key' => key})['data']
16
- end
17
-
18
- def freelancer_matches(language_pair, options)
19
- all_options = language_pair.merge!(options)
20
- self.class.get("/freelancer-matches", query: all_options, headers: { 'X-Proz-API-Key' => key})['data']
21
- end
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Proz::Client do
4
-
5
- it 'sets the client' do
6
- client = Proz::Client.new(key: 'x34454432')
7
- expect(client.key).to eq('x34454432')
8
- end
9
-
10
- it 'returns a freelancer' do
11
- client = Proz::Client.new(key: 'x34454432')
12
- expect(client.freelancer('663e4488-58a1-4713-992c-c6d90aafa3cb')['site_name']).to eq('Smartranslators')
13
- end
14
-
15
- it 'returns a freelancer match query' do
16
- client = Proz::Client.new(key: 'x34454432')
17
- language_pair = { language_pair: 'eng_esl' }
18
- options = {}
19
- expect(client.freelancer_matches(language_pair, options).size).to eq(10)
20
- end
21
- end