ruby-upwork-oauth2 2.0.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.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.docgen +1 -0
  3. data/.gitignore +22 -0
  4. data/.travis.yml +19 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +176 -0
  7. data/README.md +80 -0
  8. data/Rakefile +12 -0
  9. data/example/example.rb +65 -0
  10. data/lib/upwork/api.rb +29 -0
  11. data/lib/upwork/api/client.rb +184 -0
  12. data/lib/upwork/api/config.rb +41 -0
  13. data/lib/upwork/api/logger.rb +35 -0
  14. data/lib/upwork/api/routers/activities/engagement.rb +63 -0
  15. data/lib/upwork/api/routers/activities/team.rb +117 -0
  16. data/lib/upwork/api/routers/auth.rb +38 -0
  17. data/lib/upwork/api/routers/freelancers/profile.rb +52 -0
  18. data/lib/upwork/api/routers/freelancers/search.rb +43 -0
  19. data/lib/upwork/api/routers/hr/clients/applications.rb +55 -0
  20. data/lib/upwork/api/routers/hr/clients/offers.rb +64 -0
  21. data/lib/upwork/api/routers/hr/contracts.rb +64 -0
  22. data/lib/upwork/api/routers/hr/engagements.rb +52 -0
  23. data/lib/upwork/api/routers/hr/freelancers/applications.rb +54 -0
  24. data/lib/upwork/api/routers/hr/freelancers/offers.rb +64 -0
  25. data/lib/upwork/api/routers/hr/interviews.rb +44 -0
  26. data/lib/upwork/api/routers/hr/jobs.rb +79 -0
  27. data/lib/upwork/api/routers/hr/milestones.rb +100 -0
  28. data/lib/upwork/api/routers/hr/roles.rb +49 -0
  29. data/lib/upwork/api/routers/hr/submissions.rb +63 -0
  30. data/lib/upwork/api/routers/jobs/profile.rb +43 -0
  31. data/lib/upwork/api/routers/jobs/search.rb +43 -0
  32. data/lib/upwork/api/routers/messages.rb +129 -0
  33. data/lib/upwork/api/routers/metadata.rb +65 -0
  34. data/lib/upwork/api/routers/organization/companies.rb +67 -0
  35. data/lib/upwork/api/routers/organization/teams.rb +49 -0
  36. data/lib/upwork/api/routers/organization/users.rb +49 -0
  37. data/lib/upwork/api/routers/payments.rb +42 -0
  38. data/lib/upwork/api/routers/reports/finance/accounts.rb +56 -0
  39. data/lib/upwork/api/routers/reports/finance/billings.rb +86 -0
  40. data/lib/upwork/api/routers/reports/finance/earnings.rb +86 -0
  41. data/lib/upwork/api/routers/reports/time.rb +114 -0
  42. data/lib/upwork/api/routers/snapshot.rb +62 -0
  43. data/lib/upwork/api/routers/workdays.rb +54 -0
  44. data/lib/upwork/api/routers/workdiary.rb +42 -0
  45. data/lib/upwork/api/version.rb +18 -0
  46. data/ruby-upwork-oauth2.gemspec +27 -0
  47. data/test/helper.rb +22 -0
  48. data/test/test_activities_engagement.rb +26 -0
  49. data/test/test_activities_team.rb +46 -0
  50. data/test/test_auth.rb +16 -0
  51. data/test/test_client.rb +48 -0
  52. data/test/test_config.rb +27 -0
  53. data/test/test_freelancers_profile.rb +22 -0
  54. data/test/test_freelancers_search.rb +16 -0
  55. data/test/test_hr_clients_applications.rb +21 -0
  56. data/test/test_hr_clients_offers.rb +26 -0
  57. data/test/test_hr_contracts.rb +26 -0
  58. data/test/test_hr_engagements.rb +21 -0
  59. data/test/test_hr_freelancers_applications.rb +21 -0
  60. data/test/test_hr_freelancers_offers.rb +26 -0
  61. data/test/test_hr_interviews.rb +16 -0
  62. data/test/test_hr_jobs.rb +36 -0
  63. data/test/test_hr_milestones.rb +46 -0
  64. data/test/test_hr_roles.rb +21 -0
  65. data/test/test_hr_submissions.rb +26 -0
  66. data/test/test_jobs_profile.rb +16 -0
  67. data/test/test_jobs_search.rb +16 -0
  68. data/test/test_logger.rb +15 -0
  69. data/test/test_messages.rb +56 -0
  70. data/test/test_metadata.rb +36 -0
  71. data/test/test_organization_companies.rb +31 -0
  72. data/test/test_organization_teams.rb +21 -0
  73. data/test/test_organization_users.rb +21 -0
  74. data/test/test_payments.rb +16 -0
  75. data/test/test_reports_finance_accounts.rb +21 -0
  76. data/test/test_reports_finance_billings.rb +36 -0
  77. data/test/test_reports_finance_earnings.rb +36 -0
  78. data/test/test_reports_time.rb +41 -0
  79. data/test/test_snapshot.rb +26 -0
  80. data/test/test_workdays.rb +21 -0
  81. data/test/test_workdiary.rb +16 -0
  82. metadata +230 -0
@@ -0,0 +1,62 @@
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 2014(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
+ # Snapshot
18
+ class Snapshot
19
+ ENTRY_POINT = 'api'
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
+ # Get snapshot info by specific contract
31
+ #
32
+ # Arguments:
33
+ # contract: (String)
34
+ # ts: (String)
35
+ def get_by_contract(contract, ts)
36
+ $LOG.i "running " + __method__.to_s
37
+ @client.get '/team/v2/snapshots/contracts/' + contract + '/' + ts
38
+ end
39
+
40
+ # Update snapshot by specific contract
41
+ #
42
+ # Arguments:
43
+ # contract: (String)
44
+ # ts: (String)
45
+ # params: (Hash)
46
+ def update_by_contract(contract, ts, params)
47
+ $LOG.i "running " + __method__.to_s
48
+ @client.put '/team/v2/snapshots/contracts/' + contract + '/' + ts, params
49
+ end
50
+
51
+ # Delete snapshot by specific contract
52
+ # Arguments:
53
+ # contract: (String)
54
+ # ts: (String)
55
+ def delete_by_contract(contract, ts)
56
+ $LOG.i "running " + __method__.to_s
57
+ @client.delete '/team/v2/snapshots/contracts/' + contract + '/' + ts
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,54 @@
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 2015(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
+ # Workdays
18
+ class Workdays
19
+ ENTRY_POINT = 'api'
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
+ # Get Workdays by Company
31
+ # Arguments:
32
+ # company: (String)
33
+ # from_date: (String)
34
+ # till_date: (String)
35
+ # params: (Hash)
36
+ def get_by_company(company, from_date, till_date, params = {})
37
+ $LOG.i "running " + __method__.to_s
38
+ @client.get '/team/v2/workdays/companies/' + company + '/' + from_date + ',' + till_date, params
39
+ end
40
+
41
+ # Get Workdays by Contract
42
+ # Arguments:
43
+ # contract: (String)
44
+ # from_date: (String)
45
+ # till_date: (String)
46
+ # params: (Hash)
47
+ def get_by_contract(contract, from_date, till_date, params = {})
48
+ $LOG.i "running " + __method__.to_s
49
+ @client.get '/team/v2/workdays/contracts/' + contract + '/' + from_date + ',' + till_date, params
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,42 @@
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 2014(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
+ # Work Diary
18
+ class Workdiary
19
+ ENTRY_POINT = 'api'
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
+ # Get Work Diary by Contract
31
+ # Arguments:
32
+ # contract: (String)
33
+ # date: (String)
34
+ # params: (Hash)
35
+ def get_by_contract(contract, date, params = {})
36
+ $LOG.i "running " + __method__.to_s
37
+ @client.get '/team/v2/workdiaries/contracts/' + contract + '/' + date, params
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,18 @@
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 2018(c) Upwork.com
12
+ # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html
13
+
14
+ module Upwork # :nodoc:
15
+ module Api
16
+ VERSION = "2.0.0"
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'upwork/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby-upwork-oauth2"
8
+ spec.version = Upwork::Api::VERSION
9
+ spec.authors = ["Maksym Novozhylov"]
10
+ spec.email = ["mnovozhilov@upwork.com"]
11
+ spec.summary = %q{Ruby bindings for Upwork API (OAuth2).}
12
+ spec.description = %q{Ruby bindings for Upwork API (OAuth2) makes your life easier due to working with your Upwork's data.}
13
+ spec.homepage = "http://developers.upwork.com"
14
+ spec.license = "Apache-2.0"
15
+
16
+ spec.add_dependency 'oauth2', '~> 1.4'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 0"
25
+ spec.add_development_dependency "mocha", "~> 0"
26
+ spec.add_development_dependency "test-unit", "~> 0"
27
+ end
@@ -0,0 +1,22 @@
1
+ $:.unshift 'lib'
2
+
3
+ require 'upwork/api'
4
+
5
+ $LOG = Upwork::Api::Logger.new
6
+
7
+ module TestHelper
8
+ def get_client_mock
9
+ config = Upwork::Api::Config.new({
10
+ 'client_id' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
11
+ 'client_secret' => 'xxxxxxxxxxxxxxxx',
12
+ 'redirect_uri' => 'https://a.redirect.uri',
13
+ 'access_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
14
+ 'refresh_token' => 'xxxxxxxxxxxxxxxx',
15
+ 'debug' => false
16
+ })
17
+
18
+ client = Upwork::Api::Client.new(config)
19
+ client.expects(:send_request).returns(true)
20
+ client
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ $:.unshift 'lib'
2
+ $LOAD_PATH << File.dirname(__FILE__)
3
+
4
+ require 'helper'
5
+ require 'upwork/api/routers/activities/engagement'
6
+ require 'test/unit'
7
+ require 'mocha/test_unit'
8
+
9
+ class ActivitiesEngagementTest < Test::Unit::TestCase
10
+ include TestHelper
11
+
12
+ def test_get_specific
13
+ api = Upwork::Api::Routers::Activities::Engagement.new(get_client_mock)
14
+ assert api.get_specific('1234')
15
+ end
16
+
17
+ def test_assign
18
+ api = Upwork::Api::Routers::Activities::Engagement.new(get_client_mock)
19
+ assert api.assign('company', 'team', '1234', {})
20
+ end
21
+
22
+ def test_assign_to_engagement
23
+ api = Upwork::Api::Routers::Activities::Engagement.new(get_client_mock)
24
+ assert api.assign_to_engagement('1234', {})
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ $:.unshift 'lib'
2
+ $LOAD_PATH << File.dirname(__FILE__)
3
+
4
+ require 'helper'
5
+ require 'upwork/api/routers/activities/team'
6
+ require 'test/unit'
7
+ require 'mocha/test_unit'
8
+
9
+ class ActivitiesTeamTest < Test::Unit::TestCase
10
+ include TestHelper
11
+
12
+ def test_get_list
13
+ api = Upwork::Api::Routers::Activities::Team.new(get_client_mock)
14
+ assert api.get_list('company', 'team')
15
+ end
16
+
17
+ def test_get_specific_list
18
+ api = Upwork::Api::Routers::Activities::Team.new(get_client_mock)
19
+ assert api.get_specific_list('company', 'team', 'code')
20
+ end
21
+
22
+ def test_add_activity
23
+ api = Upwork::Api::Routers::Activities::Team.new(get_client_mock)
24
+ assert api.add_activity('company', 'team', {})
25
+ end
26
+
27
+ def test_update_activities
28
+ api = Upwork::Api::Routers::Activities::Team.new(get_client_mock)
29
+ assert api.update_activities('company', 'team', 'code', {})
30
+ end
31
+
32
+ def test_archive_activities
33
+ api = Upwork::Api::Routers::Activities::Team.new(get_client_mock)
34
+ assert api.archive_activities('company', 'team', 'code')
35
+ end
36
+
37
+ def test_unarchive_activities
38
+ api = Upwork::Api::Routers::Activities::Team.new(get_client_mock)
39
+ assert api.unarchive_activities('company', 'team', 'code')
40
+ end
41
+
42
+ def test_update_batch
43
+ api = Upwork::Api::Routers::Activities::Team.new(get_client_mock)
44
+ assert api.update_batch('company', 'data')
45
+ end
46
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift 'lib'
2
+ $LOAD_PATH << File.dirname(__FILE__)
3
+
4
+ require 'helper'
5
+ require 'upwork/api/routers/auth'
6
+ require 'test/unit'
7
+ require 'mocha/test_unit'
8
+
9
+ class AuthTest < Test::Unit::TestCase
10
+ include TestHelper
11
+
12
+ def test_get_user_info
13
+ api = Upwork::Api::Routers::Auth.new(get_client_mock)
14
+ assert api.get_user_info
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ $:.unshift 'lib'
2
+ $LOAD_PATH << File.dirname(__FILE__)
3
+
4
+ require 'helper'
5
+ require 'upwork/api/logger'
6
+ require 'upwork/api/config'
7
+ require 'upwork/api/client'
8
+ require 'test/unit'
9
+ require 'mocha/test_unit'
10
+
11
+ class ConfigTest < Test::Unit::TestCase
12
+ include TestHelper
13
+
14
+ def test_config_initialization
15
+ config = Upwork::Api::Config.new({
16
+ 'client_id' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
17
+ 'client_secret' => 'xxxxxxxxxxxxxxxx',
18
+ 'redirect_uri' => 'https://a.redirect.uri',
19
+ 'access_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
20
+ 'refresh_token' => 'xxxxxxxxxxxxxxxx',
21
+ 'debug' => false
22
+ })
23
+
24
+ client = Upwork::Api::Client.new(config)
25
+ client.epoint = 'gds'
26
+
27
+ assert_equal '/ab/account-security/oauth2/authorize',client.url_auth
28
+ assert_equal '/api/v3/oauth2/token',client.url_rtoken
29
+ assert_equal '/api/v3/oauth2/token',client.url_atoken
30
+ assert_equal 'gds',client.epoint
31
+ end
32
+
33
+ def test_get
34
+ assert get_client_mock.get('/some/api/url')
35
+ end
36
+
37
+ def test_post
38
+ assert get_client_mock.post('/some/api/url', {})
39
+ end
40
+
41
+ def test_put
42
+ assert get_client_mock.put('/some/api/url', {})
43
+ end
44
+
45
+ def test_delete
46
+ assert get_client_mock.delete('/some/api/url', {})
47
+ end
48
+ end
@@ -0,0 +1,27 @@
1
+ $:.unshift 'lib'
2
+
3
+ require 'upwork/api/config'
4
+ require 'test/unit'
5
+ require 'mocha/test_unit'
6
+
7
+ class ConfigTest < Test::Unit::TestCase
8
+ def test_my_config_initialization
9
+ config = Upwork::Api::Config.new({
10
+ 'client_id' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
11
+ 'client_secret' => 'xxxxxxxxxxxxxxxx',
12
+ 'redirect_uri' => 'https://a.redirect.uri',
13
+ 'access_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
14
+ 'refresh_token' => 'xxxxxxxxxxxxxxxx',
15
+ 'expires_at' => '0123456789',
16
+ 'debug' => false
17
+ })
18
+
19
+ assert_equal 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',config.client_id
20
+ assert_equal 'xxxxxxxxxxxxxxxx',config.client_secret
21
+ assert_equal 'https://a.redirect.uri',config.redirect_uri
22
+ assert_equal 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',config.access_token
23
+ assert_equal 'xxxxxxxxxxxxxxxx',config.refresh_token
24
+ assert_equal '0123456789',config.expires_at
25
+ assert_equal false,config.debug
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ $:.unshift 'lib'
2
+ $LOAD_PATH << File.dirname(__FILE__)
3
+
4
+ require 'helper'
5
+ require 'upwork/api/routers/freelancers/profile'
6
+ require 'test/unit'
7
+ require 'mocha/test_unit'
8
+
9
+ class FreelancersProfileTest < Test::Unit::TestCase
10
+ include TestHelper
11
+
12
+ def test_get_specific
13
+ api = Upwork::Api::Routers::Freelancers::Profile.new(get_client_mock)
14
+ assert api.get_specific('~key')
15
+ end
16
+
17
+ def test_get_specific_brief
18
+ api = Upwork::Api::Routers::Freelancers::Profile.new(get_client_mock)
19
+ assert api.get_specific_brief('~key')
20
+ end
21
+
22
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift 'lib'
2
+ $LOAD_PATH << File.dirname(__FILE__)
3
+
4
+ require 'helper'
5
+ require 'upwork/api/routers/freelancers/search'
6
+ require 'test/unit'
7
+ require 'mocha/test_unit'
8
+
9
+ class FreelancersSearchTest < Test::Unit::TestCase
10
+ include TestHelper
11
+
12
+ def test_find
13
+ api = Upwork::Api::Routers::Freelancers::Search.new(get_client_mock)
14
+ assert api.find({})
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ $:.unshift 'lib'
2
+ $LOAD_PATH << File.dirname(__FILE__)
3
+
4
+ require 'helper'
5
+ require 'upwork/api/routers/hr/clients/applications'
6
+ require 'test/unit'
7
+ require 'mocha/test_unit'
8
+
9
+ class HrClientsApplicationsTest < Test::Unit::TestCase
10
+ include TestHelper
11
+
12
+ def test_get_list
13
+ api = Upwork::Api::Routers::Hr::Clients::Applications.new(get_client_mock)
14
+ assert api.get_list({})
15
+ end
16
+
17
+ def test_get_specific
18
+ api = Upwork::Api::Routers::Hr::Clients::Applications.new(get_client_mock)
19
+ assert api.get_specific('12', {})
20
+ end
21
+ end