ruby-upwork-oauth2 2.1.4 → 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: 30396e38e7003832bc1afee54cb092275109658e4054ff0aa477f1d587075dc9
4
- data.tar.gz: dfc128c0a3fe618af664075bce4f87f3adcb9255ad653620e8ddf8dd1684f320
3
+ metadata.gz: 9c2b73f43493b0b28b2e57c5a6f0f585e6fdb5dae551c7727a08aebee090472c
4
+ data.tar.gz: 7bc58ddae0c69c0623af09ab601da75ebc90998d2d28ef8a8e9007cf1c64729d
5
5
  SHA512:
6
- metadata.gz: 71b9945740d5412cc7c80e720ba4f73ed06b70a409fd7e36f09153c33adb49d4f9fb9d5abaab818a4d3f721cd49c142688f9e630d1f50093a461470750317a64
7
- data.tar.gz: 7ad335171b968d0b6e53cb22807e781ba0f4f0f8d334df7c866075ae408c37d498222f9486260705a1d4583f75aac19444d9c2613a5fc4dfba7ffbd3e4d4dd2e
6
+ metadata.gz: 79f1166d56aab80b453ba1903f76eac2bece055edee57e3d21e43f698f56dba973339d0256e08bf5639030a2ac5ee81f85b741ec152ed7cfc08be2cd38c9f6e5
7
+ data.tar.gz: 6892be3d8566e75fc102fb2a2269f90d90a6e8089897e513b8b464ccd31f68635ed886412ccafa96802dd58930f26819e68ad4c6c0d78dd4f9966a2712c97ab0
@@ -16,7 +16,7 @@ jobs:
16
16
  fail-fast: false
17
17
  matrix:
18
18
  os: [ubuntu-latest, macos-latest]
19
- ruby: [ '2.7.3', '2.6.7', '2.5.9' ]
19
+ ruby: [ '2.7.3', '2.6.7', '3.0.1' ]
20
20
 
21
21
  name: Ruby ${{ matrix.ruby }}
22
22
  steps:
data/CHANGES.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Release History
2
2
 
3
+ ## 2.2.0
4
+ * Support Client Credentials Grant
5
+
3
6
  ## 2.1.4
4
7
  * Add GraphQL support
5
8
 
data/example/example.rb CHANGED
@@ -16,6 +16,7 @@ config = Upwork::Api::Config.new({
16
16
  'client_id' => 'xxxxxxxx',
17
17
  'client_secret' => 'xxxxxxxx',
18
18
  'redirect_uri' => 'https://a.callback.url',
19
+ # 'grant_type' => 'client_credentials' # Client Credentials Grant
19
20
  # 'access_token' => 'xxxxxxxx',
20
21
  # 'refresh_token' => 'xxxxxxxx',
21
22
  # 'expires_in' => '86399'
@@ -26,6 +27,7 @@ config = Upwork::Api::Config.new({
26
27
  # setup client
27
28
  client = Upwork::Api::Client.new(config)
28
29
 
30
+ # Code Authorization Grant
29
31
  # run authorization in case we haven't done it yet
30
32
  # and do not have an access and refresh token pair
31
33
  if !config.access_token and !config.refresh_token
@@ -38,6 +40,11 @@ if !config.access_token and !config.refresh_token
38
40
  # store access token data in safe place!
39
41
  end
40
42
 
43
+ # Client Credentials Grant
44
+ if !config.access_token
45
+ @token = client.get_access_token
46
+ end
47
+
41
48
  # WARNING: the access token will be refreshed automatically for you
42
49
  # in case it's expired, i.e. expires_at < time(). Make sure you replace the
43
50
  # old token accordingly in your security storage. Call client.get_actual_config
@@ -60,10 +60,16 @@ module Upwork
60
60
  #
61
61
  # Arguments:
62
62
  # authz_code: (String)
63
- def get_access_token(authz_code)
64
- $LOG.i "getting access and refresh token pair"
65
- @access_token = @oauth2_client.auth_code.get_token(authz_code, :redirect_uri => @config.redirect_uri)
66
- $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
67
73
 
68
74
  refresh_config_from_access_token
69
75
 
@@ -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.4"
16
+ VERSION = "2.2.0"
17
17
  end
18
18
  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.4
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: 2021-12-27 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
@@ -119,6 +119,7 @@ files:
119
119
  - lib/upwork/api/routers/auth.rb
120
120
  - lib/upwork/api/routers/freelancers/profile.rb
121
121
  - lib/upwork/api/routers/freelancers/search.rb
122
+ - lib/upwork/api/routers/graphql.rb
122
123
  - lib/upwork/api/routers/hr/clients/applications.rb
123
124
  - lib/upwork/api/routers/hr/clients/offers.rb
124
125
  - lib/upwork/api/routers/hr/contracts.rb
@@ -155,6 +156,7 @@ files:
155
156
  - test/test_config.rb
156
157
  - test/test_freelancers_profile.rb
157
158
  - test/test_freelancers_search.rb
159
+ - test/test_graphql.rb
158
160
  - test/test_hr_clients_applications.rb
159
161
  - test/test_hr_clients_offers.rb
160
162
  - test/test_hr_contracts.rb
@@ -201,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
203
  - !ruby/object:Gem::Version
202
204
  version: '0'
203
205
  requirements: []
204
- rubygems_version: 3.2.5
206
+ rubygems_version: 3.3.5
205
207
  signing_key:
206
208
  specification_version: 4
207
209
  summary: Ruby bindings for Upwork API (OAuth2).
@@ -214,6 +216,7 @@ test_files:
214
216
  - test/test_config.rb
215
217
  - test/test_freelancers_profile.rb
216
218
  - test/test_freelancers_search.rb
219
+ - test/test_graphql.rb
217
220
  - test/test_hr_clients_applications.rb
218
221
  - test/test_hr_clients_offers.rb
219
222
  - test/test_hr_contracts.rb