ruby-upwork-oauth2 2.1.4 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +1 -1
- data/CHANGES.md +3 -0
- data/example/example.rb +7 -0
- data/lib/upwork/api/client.rb +10 -4
- data/lib/upwork/api/config.rb +2 -2
- data/lib/upwork/api/routers/graphql.rb +38 -0
- data/lib/upwork/api/version.rb +1 -1
- data/test/test_graphql.rb +16 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c2b73f43493b0b28b2e57c5a6f0f585e6fdb5dae551c7727a08aebee090472c
|
4
|
+
data.tar.gz: 7bc58ddae0c69c0623af09ab601da75ebc90998d2d28ef8a8e9007cf1c64729d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79f1166d56aab80b453ba1903f76eac2bece055edee57e3d21e43f698f56dba973339d0256e08bf5639030a2ac5ee81f85b741ec152ed7cfc08be2cd38c9f6e5
|
7
|
+
data.tar.gz: 6892be3d8566e75fc102fb2a2269f90d90a6e8089897e513b8b464ccd31f68635ed886412ccafa96802dd58930f26819e68ad4c6c0d78dd4f9966a2712c97ab0
|
data/.github/workflows/build.yml
CHANGED
data/CHANGES.md
CHANGED
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
|
data/lib/upwork/api/client.rb
CHANGED
@@ -60,10 +60,16 @@ module Upwork
|
|
60
60
|
#
|
61
61
|
# Arguments:
|
62
62
|
# authz_code: (String)
|
63
|
-
def get_access_token(authz_code)
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
|
data/lib/upwork/api/config.rb
CHANGED
@@ -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
|
data/lib/upwork/api/version.rb
CHANGED
@@ -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.
|
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:
|
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.
|
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
|