ruby-upwork-oauth2 2.1.3 → 2.2.0

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
  SHA256:
3
- metadata.gz: ae0c55c23aa24352c0f7abbb6e8997c9ddd9a569f18e51073d677ee1db27de56
4
- data.tar.gz: 1146d2241c4ef5309dcbfa9437cfe07531e72c5c61b5fbf1188a7279802e4ac1
3
+ metadata.gz: 9c2b73f43493b0b28b2e57c5a6f0f585e6fdb5dae551c7727a08aebee090472c
4
+ data.tar.gz: 7bc58ddae0c69c0623af09ab601da75ebc90998d2d28ef8a8e9007cf1c64729d
5
5
  SHA512:
6
- metadata.gz: 7de51dee4754a23762d8641acb725641838942563bcef8389058db5dd915e624105242d5266c932d833c85ebdd3c085b7ccfd57369eace355d8640aac135e4b0
7
- data.tar.gz: '064596e784a903ca8415a130a9df988ead4082dbe6ac2037dc6cbd55d9920f1dd6f97e979604070c8a761a55250579f203e7278456cea262c555dda69773e483'
6
+ metadata.gz: 79f1166d56aab80b453ba1903f76eac2bece055edee57e3d21e43f698f56dba973339d0256e08bf5639030a2ac5ee81f85b741ec152ed7cfc08be2cd38c9f6e5
7
+ data.tar.gz: 6892be3d8566e75fc102fb2a2269f90d90a6e8089897e513b8b464ccd31f68635ed886412ccafa96802dd58930f26819e68ad4c6c0d78dd4f9966a2712c97ab0
@@ -0,0 +1,34 @@
1
+ name: build
2
+
3
+ on:
4
+ push:
5
+ paths-ignore:
6
+ - '**.md'
7
+ pull_request:
8
+ paths-ignore:
9
+ - '**.md'
10
+
11
+ jobs:
12
+ test:
13
+
14
+ runs-on: ${{ matrix.os }}
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ os: [ubuntu-latest, macos-latest]
19
+ ruby: [ '2.7.3', '2.6.7', '3.0.1' ]
20
+
21
+ name: Ruby ${{ matrix.ruby }}
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ # step 1: setup
25
+ - name: Setup ruby
26
+ uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
27
+ with:
28
+ ruby-version: ${{ matrix.ruby }}
29
+ # step 2: install dependencies
30
+ - name: Install dependencies
31
+ run: gem install oauth2 test-unit mocha
32
+ # step 3: run test
33
+ - name: Run tests
34
+ run: rake test
data/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ## 2.2.0
4
+ * Support Client Credentials Grant
5
+
6
+ ## 2.1.4
7
+ * Add GraphQL support
8
+
3
9
  ## 2.1.3
4
10
  * Send Message to a Batch of Rooms API
5
11
 
data/README.md CHANGED
@@ -4,8 +4,7 @@ Ruby bindings for Upwork API (OAuth2)
4
4
  [![License](https://img.shields.io/github/license/upwork/ruby-upwork-oauth2)](http://www.apache.org/licenses/LICENSE-2.0.html)
5
5
  [![Gem Version](https://badge.fury.io/rb/ruby-upwork-oauth2.svg)](http://badge.fury.io/rb/ruby-upwork-oauth2)
6
6
  [![GitHub release](https://img.shields.io/github/release/upwork/ruby-upwork-oauth2.svg)](https://github.com/upwork/ruby-upwork-oauth2/releases)
7
- [![Build Status](https://travis-ci.org/upwork/ruby-upwork-oauth2.svg)](https://travis-ci.org/upwork/ruby-upwork-oauth2)
8
- [![Stories in Ready](http://badge.waffle.io/upwork/ruby-upwork-oauth2.png)](http://waffle.io/upwork/ruby-upwork-oauth2)
7
+ [![Build Status](https://github.com/upwork/ruby-upwork-oauth2/workflows/build/badge.svg)](https://github.com/upwork/ruby-upwork-oauth2/actions)
9
8
 
10
9
  # Upwork::Api
11
10
 
data/example/example.rb CHANGED
@@ -5,6 +5,7 @@ $:.unshift '../lib'
5
5
  $LOAD_PATH << File.dirname(__FILE__)
6
6
 
7
7
  require 'upwork/api'
8
+ require 'upwork/api/routers/graphql'
8
9
  require 'upwork/api/routers/auth'
9
10
  require 'upwork/api/routers/messages'
10
11
  require 'upwork/api/routers/reports/time'
@@ -15,6 +16,7 @@ config = Upwork::Api::Config.new({
15
16
  'client_id' => 'xxxxxxxx',
16
17
  'client_secret' => 'xxxxxxxx',
17
18
  'redirect_uri' => 'https://a.callback.url',
19
+ # 'grant_type' => 'client_credentials' # Client Credentials Grant
18
20
  # 'access_token' => 'xxxxxxxx',
19
21
  # 'refresh_token' => 'xxxxxxxx',
20
22
  # 'expires_in' => '86399'
@@ -25,6 +27,7 @@ config = Upwork::Api::Config.new({
25
27
  # setup client
26
28
  client = Upwork::Api::Client.new(config)
27
29
 
30
+ # Code Authorization Grant
28
31
  # run authorization in case we haven't done it yet
29
32
  # and do not have an access and refresh token pair
30
33
  if !config.access_token and !config.refresh_token
@@ -37,12 +40,35 @@ if !config.access_token and !config.refresh_token
37
40
  # store access token data in safe place!
38
41
  end
39
42
 
43
+ # Client Credentials Grant
44
+ if !config.access_token
45
+ @token = client.get_access_token
46
+ end
47
+
40
48
  # WARNING: the access token will be refreshed automatically for you
41
49
  # in case it's expired, i.e. expires_at < time(). Make sure you replace the
42
50
  # old token accordingly in your security storage. Call client.get_actual_config
43
51
  # periodically to sync-up the data
44
52
  @actual_access_token_data = client.get_actual_config
45
53
 
54
+ # execute graphql request
55
+ #client.set_org_uid_header('1234567890') # Organization UID (optional)
56
+ #graphql = Upwork::Api::Routers::Graphql.new(client)
57
+ #params = {
58
+ # 'query' => "query {
59
+ # user {
60
+ # id
61
+ # nid
62
+ # rid
63
+ # }
64
+ # organization {
65
+ # id
66
+ # }
67
+ # }"
68
+ #}
69
+ #data = graphql.execute params
70
+ #p data['data']['user']['id']
71
+
46
72
  # get my auth data
47
73
  #auth = Upwork::Api::Routers::Auth.new(client)
48
74
  #info = auth.get_user_info
@@ -37,6 +37,7 @@ module Upwork
37
37
  @config = config
38
38
  @epoint = Upwork::Api::DEFAULT_EPOINT
39
39
  @url_auth, @url_rtoken, @url_atoken = URI_AUTH, URI_RTOKEN, URI_ATOKEN
40
+ @tenant_id = nil
40
41
 
41
42
  @oauth2_client = OAuth2::Client.new(
42
43
  @config.client_id,
@@ -59,10 +60,16 @@ module Upwork
59
60
  #
60
61
  # Arguments:
61
62
  # authz_code: (String)
62
- def get_access_token(authz_code)
63
- $LOG.i "getting access and refresh token pair"
64
- @access_token = @oauth2_client.auth_code.get_token(authz_code, :redirect_uri => @config.redirect_uri)
65
- $LOG.i "got access and refresh token pair", @access_token
63
+ def get_access_token(authz_code = nil)
64
+ if @config.grant_type == 'client_credentials'
65
+ $LOG.i "getting access token"
66
+ @access_token = @oauth2_client.client_credentials.get_token
67
+ $LOG.i "got access token", @access_token
68
+ else
69
+ $LOG.i "getting access and refresh token pair"
70
+ @access_token = @oauth2_client.auth_code.get_token(authz_code, :redirect_uri => @config.redirect_uri)
71
+ $LOG.i "got access and refresh token pair", @access_token
72
+ end
66
73
 
67
74
  refresh_config_from_access_token
68
75
 
@@ -73,6 +80,11 @@ module Upwork
73
80
  def get_actual_config
74
81
  @config
75
82
  end
83
+
84
+ # Configure X-Upwork-API-TenantId header
85
+ def set_org_uid_header(tenant_id)
86
+ @tenant_id = tenant_id
87
+ end
76
88
 
77
89
  # Run GET request
78
90
  #
@@ -117,7 +129,7 @@ module Upwork
117
129
 
118
130
  # Get URI with :format
119
131
  def get_uri_with_format(uri) # :nodoc:
120
- (@epoint) + uri + ((@epoint == 'api') ? '.' + DATA_FORMAT : '')
132
+ (@epoint == 'graphql') ? Upwork::Api::GQL_EPOINT : ((@epoint) + uri + ((@epoint == 'api') ? '.' + DATA_FORMAT : ''))
121
133
  end
122
134
 
123
135
  private
@@ -172,7 +184,15 @@ module Upwork
172
184
  url = get_url_with_params get_uri_with_format(uri), params
173
185
  response = @access_token.get(url).body
174
186
  when :post, :put, :delete
175
- response = @access_token.post(get_uri_with_format(uri), {body: params}).body
187
+ if @epoint == 'graphql'
188
+ data = {:body => params.to_json, :headers => {'Content-Type' => 'application/json'}}
189
+ if @tenant_id
190
+ data[:headers]['X-Upwork-API-TenantId'] = @tenant_id
191
+ end
192
+ else
193
+ data = {body: params}
194
+ end
195
+ response = @access_token.post(get_uri_with_format(uri), data).body
176
196
  else
177
197
  raise ArgumentError, "Don't know how to handle http method: :#{method.to_s}"
178
198
  end
@@ -18,14 +18,14 @@ module Upwork
18
18
  @@debug = false;
19
19
 
20
20
  attr_accessor :access_token, :refresh_token, :expires_in, :expires_at
21
- attr_reader :client_id, :client_secret, :redirect_uri
21
+ attr_reader :client_id, :client_secret, :redirect_uri, :grant_type
22
22
 
23
23
  # Init config object
24
24
  #
25
25
  # Arguments:
26
26
  # config: (Hash)
27
27
  def initialize(config = {})
28
- @client_id, @client_secret, @redirect_uri = config['client_id'], config['client_secret'], config['redirect_uri']
28
+ @client_id, @client_secret, @redirect_uri, @grant_type = config['client_id'], config['client_secret'], config['redirect_uri'], config['grant_type']
29
29
  @access_token, @refresh_token, @expires_in, @expires_at = config['access_token'], config['refresh_token'], config['expires_in'], config['expires_at']
30
30
  @@debug = config['debug']
31
31
 
@@ -0,0 +1,38 @@
1
+ # Licensed under the Upwork's API Terms of Use;
2
+ # you may not use this file except in compliance with the Terms.
3
+ #
4
+ # Unless required by applicable law or agreed to in writing, software
5
+ # distributed under the License is distributed on an "AS IS" BASIS,
6
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7
+ # See the License for the specific language governing permissions and
8
+ # limitations under the License.
9
+ #
10
+ # Author:: Maksym Novozhylov (mnovozhilov@upwork.com)
11
+ # Copyright:: Copyright 2021(c) Upwork.com
12
+ # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html
13
+
14
+ module Upwork
15
+ module Api
16
+ module Routers
17
+ # Execute GraphQL requests
18
+ class Graphql
19
+ ENTRY_POINT = 'graphql'
20
+
21
+ # Init
22
+ #
23
+ # Arguments:
24
+ # client: (Client)
25
+ def initialize(client)
26
+ @client = client
27
+ @client.epoint = ENTRY_POINT
28
+ end
29
+
30
+ # Execute GraphQL request
31
+ def execute(params)
32
+ $LOG.i "running " + __method__.to_s
33
+ @client.post '', params
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -13,6 +13,6 @@
13
13
 
14
14
  module Upwork # :nodoc:
15
15
  module Api
16
- VERSION = "2.1.3"
16
+ VERSION = "2.2.0"
17
17
  end
18
18
  end
data/lib/upwork/api.rb CHANGED
@@ -23,6 +23,7 @@ module Upwork # :nodoc:
23
23
  # define some constants
24
24
  BASE_HOST = 'https://www.upwork.com'
25
25
  DEFAULT_EPOINT = 'api'
26
+ GQL_EPOINT = 'https://api.upwork.com/graphql'
26
27
 
27
28
  $LOG = Logger.new
28
29
  end
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.6"
24
- spec.add_development_dependency "rake", ">= 12.3.3"
23
+ spec.add_development_dependency "bundler", "~> 2.2", ">= 2.2.10"
24
+ spec.add_development_dependency "rake", "~>12.3", ">= 12.3.3"
25
25
  spec.add_development_dependency "mocha", "~> 0"
26
26
  spec.add_development_dependency "test-unit", "~> 0"
27
27
  end
@@ -0,0 +1,16 @@
1
+ $:.unshift 'lib'
2
+ $LOAD_PATH << File.dirname(__FILE__)
3
+
4
+ require 'helper'
5
+ require 'upwork/api/routers/graphql'
6
+ require 'test/unit'
7
+ require 'mocha/test_unit'
8
+
9
+ class GraphqlTest < Test::Unit::TestCase
10
+ include TestHelper
11
+
12
+ def test_execute
13
+ api = Upwork::Api::Routers::Graphql.new(get_client_mock)
14
+ assert api.execute({'query': 'query{}'})
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-upwork-oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maksym Novozhylov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-18 00:00:00.000000000 Z
11
+ date: 2023-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -30,18 +30,27 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '2.2'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.2.10
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
- version: '1.6'
43
+ version: '2.2'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.2.10
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rake
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '12.3'
45
54
  - - ">="
46
55
  - !ruby/object:Gem::Version
47
56
  version: 12.3.3
@@ -49,6 +58,9 @@ dependencies:
49
58
  prerelease: false
50
59
  version_requirements: !ruby/object:Gem::Requirement
51
60
  requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '12.3'
52
64
  - - ">="
53
65
  - !ruby/object:Gem::Version
54
66
  version: 12.3.3
@@ -89,9 +101,9 @@ extensions: []
89
101
  extra_rdoc_files: []
90
102
  files:
91
103
  - ".docgen"
104
+ - ".github/workflows/build.yml"
92
105
  - ".gitignore"
93
106
  - ".tests"
94
- - ".travis.yml"
95
107
  - CHANGES.md
96
108
  - Gemfile
97
109
  - LICENSE.txt
@@ -107,6 +119,7 @@ files:
107
119
  - lib/upwork/api/routers/auth.rb
108
120
  - lib/upwork/api/routers/freelancers/profile.rb
109
121
  - lib/upwork/api/routers/freelancers/search.rb
122
+ - lib/upwork/api/routers/graphql.rb
110
123
  - lib/upwork/api/routers/hr/clients/applications.rb
111
124
  - lib/upwork/api/routers/hr/clients/offers.rb
112
125
  - lib/upwork/api/routers/hr/contracts.rb
@@ -143,6 +156,7 @@ files:
143
156
  - test/test_config.rb
144
157
  - test/test_freelancers_profile.rb
145
158
  - test/test_freelancers_search.rb
159
+ - test/test_graphql.rb
146
160
  - test/test_hr_clients_applications.rb
147
161
  - test/test_hr_clients_offers.rb
148
162
  - test/test_hr_contracts.rb
@@ -189,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
203
  - !ruby/object:Gem::Version
190
204
  version: '0'
191
205
  requirements: []
192
- rubygems_version: 3.1.2
206
+ rubygems_version: 3.3.5
193
207
  signing_key:
194
208
  specification_version: 4
195
209
  summary: Ruby bindings for Upwork API (OAuth2).
@@ -202,6 +216,7 @@ test_files:
202
216
  - test/test_config.rb
203
217
  - test/test_freelancers_profile.rb
204
218
  - test/test_freelancers_search.rb
219
+ - test/test_graphql.rb
205
220
  - test/test_hr_clients_applications.rb
206
221
  - test/test_hr_clients_offers.rb
207
222
  - test/test_hr_contracts.rb
data/.travis.yml DELETED
@@ -1,18 +0,0 @@
1
- language: ruby
2
- script: rake
3
- rvm:
4
- - 2.3.0
5
- - 2.4.3
6
- - 2.5.0
7
- - jruby-head
8
- - ruby-head
9
- install: gem install oauth2 test-unit mocha
10
- matrix:
11
- allow_failures:
12
- - rvm: ruby-head
13
- fast_finish: true
14
- notifications:
15
- email:
16
- recipients:
17
- - apisupport@upwork.com
18
- on_failure: change