├── .docgen ├── .tests ├── Gemfile ├── .gitignore ├── Rakefile ├── test ├── test_logger.rb ├── test_auth.rb ├── test_jobs_search.rb ├── test_hr_interviews.rb ├── test_payments.rb ├── test_jobs_profile.rb ├── test_freelancers_search.rb ├── test_hr_roles.rb ├── test_hr_engagements.rb ├── test_workdiary.rb ├── helper.rb ├── test_organization_teams.rb ├── test_organization_users.rb ├── test_hr_clients_applications.rb ├── test_workdays.rb ├── test_freelancers_profile.rb ├── test_reports_finance_accounts.rb ├── test_hr_freelancers_applications.rb ├── test_hr_submissions.rb ├── test_hr_clients_offers.rb ├── test_hr_contracts.rb ├── test_hr_freelancers_offers.rb ├── test_snapshot.rb ├── test_activities_engagement.rb ├── test_organization_companies.rb ├── test_config.rb ├── test_hr_jobs.rb ├── test_reports_finance_billings.rb ├── test_reports_finance_earnings.rb ├── test_metadata.rb ├── test_hr_milestones.rb ├── test_reports_time.rb ├── test_client.rb ├── test_activities_team.rb └── test_messages.rb ├── CHANGES.md ├── lib └── upwork │ ├── api │ ├── version.rb │ ├── logger.rb │ ├── routers │ │ ├── auth.rb │ │ ├── jobs │ │ │ ├── search.rb │ │ │ └── profile.rb │ │ ├── payments.rb │ │ ├── freelancers │ │ │ ├── search.rb │ │ │ └── profile.rb │ │ ├── hr │ │ │ ├── interviews.rb │ │ │ ├── roles.rb │ │ │ ├── engagements.rb │ │ │ ├── freelancers │ │ │ │ ├── applications.rb │ │ │ │ └── offers.rb │ │ │ ├── clients │ │ │ │ ├── applications.rb │ │ │ │ └── offers.rb │ │ │ ├── contracts.rb │ │ │ ├── submissions.rb │ │ │ ├── jobs.rb │ │ │ └── milestones.rb │ │ ├── organization │ │ │ ├── teams.rb │ │ │ ├── users.rb │ │ │ └── companies.rb │ │ ├── workdiary.rb │ │ ├── workdays.rb │ │ ├── reports │ │ │ ├── finance │ │ │ │ ├── accounts.rb │ │ │ │ ├── billings.rb │ │ │ │ └── earnings.rb │ │ │ └── time.rb │ │ ├── snapshot.rb │ │ ├── activities │ │ │ ├── engagement.rb │ │ │ └── team.rb │ │ ├── metadata.rb │ │ └── messages.rb │ ├── config.rb │ └── client.rb │ └── api.rb ├── .github └── workflows │ └── build.yml ├── upwork-api.gemspec ├── example └── myapp.rb ├── README.md └── LICENSE.txt /.docgen: -------------------------------------------------------------------------------- 1 | rdoc 2 | -------------------------------------------------------------------------------- /.tests: -------------------------------------------------------------------------------- 1 | rake test 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in upwork-api.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | *.bundle 19 | *.so 20 | *.o 21 | *.a 22 | mkmf.log 23 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | %w[rubygems rake rake/clean rake/testtask fileutils].each { |f| require f } 2 | $LOAD_PATH << File.dirname(__FILE__) + '/lib' 3 | require 'bundler/gem_tasks' 4 | require 'oauth' 5 | 6 | Rake::TestTask.new do |t| 7 | t.libs << "test" 8 | t.test_files = FileList['test/*test_*.rb'] 9 | t.verbose = true 10 | end 11 | 12 | task :default => :test 13 | -------------------------------------------------------------------------------- /test/test_logger.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | 3 | require 'upwork/api/logger' 4 | require 'test/unit' 5 | require 'mocha/test_unit' 6 | 7 | class LoggerTest < Test::Unit::TestCase 8 | def test_i 9 | $DEBUG = true 10 | @log = Upwork::Api::Logger.new 11 | @log.expects(:puts).with("> bar") 12 | @log.i "bar" 13 | $DEBUG = false 14 | end 15 | end -------------------------------------------------------------------------------- /test/test_auth.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /test/test_jobs_search.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/jobs/search' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class JobsSearchTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_find 13 | api = Upwork::Api::Routers::Jobs::Search.new(get_client_mock) 14 | assert api.find({}) 15 | end 16 | end -------------------------------------------------------------------------------- /test/test_hr_interviews.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/interviews' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrInterviewsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_invite 13 | api = Upwork::Api::Routers::Hr::Interviews.new(get_client_mock) 14 | assert api.invite('key', {}) 15 | end 16 | end -------------------------------------------------------------------------------- /test/test_payments.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/payments' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class PaymentsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_submit_bonus 13 | api = Upwork::Api::Routers::Payments.new(get_client_mock) 14 | assert api.submit_bonus('12', {}) 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /test/test_jobs_profile.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/jobs/profile' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class JobsProfileTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_specific 13 | api = Upwork::Api::Routers::Jobs::Profile.new(get_client_mock) 14 | assert api.get_specific('~key') 15 | end 16 | end -------------------------------------------------------------------------------- /test/test_freelancers_search.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Release History 2 | 3 | ## 1.3.5 4 | * Send Message to a Batch of Rooms API 5 | * Bug fixes 6 | 7 | ## 1.3.4 8 | * Add Room Messages API 9 | 10 | ## 1.3.3 11 | * Add Specialties API 12 | * Add Skills V2 API 13 | 14 | ## 1.3.2 15 | * Fix the broken URL in assign method of Activities API 16 | 17 | ## 1.3.1 18 | * Fix assign_to_engagement - parameters are not sent 19 | 20 | ## 1.3.0 21 | * Stop supporting deprecated Teamrooms API 22 | * Migrate Workdiaries, Workdays and Snapshots API to v3 23 | -------------------------------------------------------------------------------- /test/test_hr_roles.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/roles' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrRolesTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_all 13 | api = Upwork::Api::Routers::Hr::Roles.new(get_client_mock) 14 | assert api.get_all 15 | end 16 | 17 | def test_get_by_specific_user 18 | api = Upwork::Api::Routers::Hr::Roles.new(get_client_mock) 19 | assert api.get_by_specific_user('12') 20 | end 21 | end -------------------------------------------------------------------------------- /test/test_hr_engagements.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/engagements' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrEngagementsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_list 13 | api = Upwork::Api::Routers::Hr::Engagements.new(get_client_mock) 14 | assert api.get_list({}) 15 | end 16 | 17 | def test_get_specific 18 | api = Upwork::Api::Routers::Hr::Engagements.new(get_client_mock) 19 | assert api.get_specific('12') 20 | end 21 | end -------------------------------------------------------------------------------- /test/test_workdiary.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/workdiary' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class WorkdiaryTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get 13 | api = Upwork::Api::Routers::Workdiary.new(get_client_mock) 14 | assert api.get('company', '20140101', {}) 15 | end 16 | 17 | def test_get_by_contract 18 | api = Upwork::Api::Routers::Workdiary.new(get_client_mock) 19 | assert api.get_by_contract('1234', '20140101', {}) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/helper.rb: -------------------------------------------------------------------------------- 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 | 'consumer_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 11 | 'consumer_secret' => 'xxxxxxxxxxxxxxxx', 12 | 'access_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 13 | 'access_secret' => 'xxxxxxxxxxxxxxxx', 14 | 'debug' => false 15 | }) 16 | 17 | client = Upwork::Api::Client.new(config) 18 | client.expects(:send_request).returns(true) 19 | client 20 | end 21 | end -------------------------------------------------------------------------------- /test/test_organization_teams.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/organization/teams' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class OrganizationTeamsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_list 13 | api = Upwork::Api::Routers::Organization::Teams.new(get_client_mock) 14 | assert api.get_list 15 | end 16 | 17 | def test_get_users_in_team 18 | api = Upwork::Api::Routers::Organization::Teams.new(get_client_mock) 19 | assert api.get_users_in_team('12') 20 | end 21 | end -------------------------------------------------------------------------------- /test/test_organization_users.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/organization/users' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class OrganizationUsersTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_my_info 13 | api = Upwork::Api::Routers::Organization::Users.new(get_client_mock) 14 | assert api.get_my_info 15 | end 16 | 17 | def test_get_specific 18 | api = Upwork::Api::Routers::Organization::Users.new(get_client_mock) 19 | assert api.get_specific('12') 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/test_hr_clients_applications.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /test/test_workdays.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/workdays' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class WorkdaysTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_by_company 13 | api = Upwork::Api::Routers::Workdays.new(get_client_mock) 14 | assert api.get_by_company('company', '20140101', '20140131', {}) 15 | end 16 | 17 | def test_get_by_contract 18 | api = Upwork::Api::Routers::Workdays.new(get_client_mock) 19 | assert api.get_by_contract('1234', '20140101', '20140131', {}) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/test_freelancers_profile.rb: -------------------------------------------------------------------------------- 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 23 | -------------------------------------------------------------------------------- /test/test_reports_finance_accounts.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/reports/finance/accounts' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class ReportsFinanceAccountsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_owned 13 | api = Upwork::Api::Routers::Reports::Finance::Accounts.new(get_client_mock) 14 | assert api.get_owned('12', {}) 15 | end 16 | 17 | def test_get_specific 18 | api = Upwork::Api::Routers::Reports::Finance::Accounts.new(get_client_mock) 19 | assert api.get_specific('12', {}) 20 | end 21 | end -------------------------------------------------------------------------------- /test/test_hr_freelancers_applications.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/freelancers/applications' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrFreelancersApplicationsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_list 13 | api = Upwork::Api::Routers::Hr::Freelancers::Applications.new(get_client_mock) 14 | assert api.get_list({}) 15 | end 16 | 17 | def test_get_specific 18 | api = Upwork::Api::Routers::Hr::Freelancers::Applications.new(get_client_mock) 19 | assert api.get_specific('12') 20 | end 21 | end -------------------------------------------------------------------------------- /test/test_hr_submissions.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/submissions' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrSubmissionsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_request_approval 13 | api = Upwork::Api::Routers::Hr::Submissions.new(get_client_mock) 14 | assert api.request_approval({}) 15 | end 16 | 17 | def test_approve 18 | api = Upwork::Api::Routers::Hr::Submissions.new(get_client_mock) 19 | assert api.approve('1234', {}) 20 | end 21 | 22 | def test_reject 23 | api = Upwork::Api::Routers::Hr::Submissions.new(get_client_mock) 24 | assert api.reject('1234', {}) 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/upwork/api/version.rb: -------------------------------------------------------------------------------- 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 # :nodoc: 15 | module Api 16 | VERSION = "1.3.5" 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /test/test_hr_clients_offers.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/clients/offers' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrClientsOffersTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_list 13 | api = Upwork::Api::Routers::Hr::Clients::Offers.new(get_client_mock) 14 | assert api.get_list({}) 15 | end 16 | 17 | def test_get_specific 18 | api = Upwork::Api::Routers::Hr::Clients::Offers.new(get_client_mock) 19 | assert api.get_specific('12', {}) 20 | end 21 | 22 | def test_make_offer 23 | api = Upwork::Api::Routers::Hr::Clients::Offers.new(get_client_mock) 24 | assert api.make_offer({}) 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /test/test_hr_contracts.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/contracts' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrContractsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_suspend_contract 13 | api = Upwork::Api::Routers::Hr::Contracts.new(get_client_mock) 14 | assert api.suspend_contract('12', {}) 15 | end 16 | 17 | def test_restart_contract 18 | api = Upwork::Api::Routers::Hr::Contracts.new(get_client_mock) 19 | assert api.restart_contract('12', {}) 20 | end 21 | 22 | def test_end_contract 23 | api = Upwork::Api::Routers::Hr::Contracts.new(get_client_mock) 24 | assert api.end_contract('12', {}) 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /test/test_hr_freelancers_offers.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/freelancers/offers' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrFreelancersOffersTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_list 13 | api = Upwork::Api::Routers::Hr::Freelancers::Offers.new(get_client_mock) 14 | assert api.get_list({}) 15 | end 16 | 17 | def test_get_specific 18 | api = Upwork::Api::Routers::Hr::Freelancers::Offers.new(get_client_mock) 19 | assert api.get_specific('12') 20 | end 21 | 22 | def test_actions 23 | api = Upwork::Api::Routers::Hr::Freelancers::Offers.new(get_client_mock) 24 | assert api.actions('12', {}) 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /test/test_snapshot.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/snapshot' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class SnapshotTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_by_contract 13 | api = Upwork::Api::Routers::Snapshot.new(get_client_mock) 14 | assert api.get_by_contract('contract', '20140101') 15 | end 16 | 17 | def test_update_by_contract 18 | api = Upwork::Api::Routers::Snapshot.new(get_client_mock) 19 | assert api.update_by_contract('contract', '20140101', {}) 20 | end 21 | 22 | def test_delete_by_contract 23 | api = Upwork::Api::Routers::Snapshot.new(get_client_mock) 24 | assert api.delete_by_contract('contract', '20140101') 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /test/test_activities_engagement.rb: -------------------------------------------------------------------------------- 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 27 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 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', '2.5.9' ] 20 | 21 | name: Ruby ${{ matrix.ruby }} 22 | steps: 23 | - uses: actions/checkout@v2 24 | - name: Setup ruby 25 | uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6 26 | with: 27 | ruby-version: ${{ matrix.ruby }} 28 | # step 1: install dependencies 29 | - name: Install dependencies 30 | run: gem install oauth test-unit mocha 31 | # step 2: run test 32 | - name: Run tests 33 | run: rake test 34 | -------------------------------------------------------------------------------- /test/test_organization_companies.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/organization/companies' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class OrganizationCompaniesTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_list 13 | api = Upwork::Api::Routers::Organization::Companies.new(get_client_mock) 14 | assert api.get_list 15 | end 16 | 17 | def test_get_specific 18 | api = Upwork::Api::Routers::Organization::Companies.new(get_client_mock) 19 | assert api.get_specific('12') 20 | end 21 | 22 | def test_get_teams 23 | api = Upwork::Api::Routers::Organization::Companies.new(get_client_mock) 24 | assert api.get_teams('12') 25 | end 26 | 27 | def test_get_users 28 | api = Upwork::Api::Routers::Organization::Companies.new(get_client_mock) 29 | assert api.get_users('12') 30 | end 31 | end -------------------------------------------------------------------------------- /test/test_config.rb: -------------------------------------------------------------------------------- 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 | 'consumer_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 11 | 'consumer_secret' => 'xxxxxxxxxxxxxxxx', 12 | 'access_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 13 | 'access_secret' => 'xxxxxxxxxxxxxxxx', 14 | 'signature_method'=> 'sig', 15 | 'debug' => false 16 | }) 17 | 18 | assert_equal 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',config.consumer_key 19 | assert_equal 'xxxxxxxxxxxxxxxx',config.consumer_secret 20 | assert_equal 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',config.access_token 21 | assert_equal 'xxxxxxxxxxxxxxxx',config.access_secret 22 | assert_equal 'sig',config.signature_method 23 | assert_equal false,config.debug 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/test_hr_jobs.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/jobs' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrJobsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_list 13 | api = Upwork::Api::Routers::Hr::Jobs.new(get_client_mock) 14 | assert api.get_list({}) 15 | end 16 | 17 | def test_ 18 | api = Upwork::Api::Routers::Hr::Jobs.new(get_client_mock) 19 | assert api.get_specific('key') 20 | end 21 | 22 | def test_post_job 23 | api = Upwork::Api::Routers::Hr::Jobs.new(get_client_mock) 24 | assert api.post_job({}) 25 | end 26 | 27 | def test_edit_job 28 | api = Upwork::Api::Routers::Hr::Jobs.new(get_client_mock) 29 | assert api.edit_job('key', {}) 30 | end 31 | 32 | def test_delete_job 33 | api = Upwork::Api::Routers::Hr::Jobs.new(get_client_mock) 34 | assert api.delete_job('key', {}) 35 | end 36 | end -------------------------------------------------------------------------------- /lib/upwork/api.rb: -------------------------------------------------------------------------------- 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 | require 'oauth' 15 | 16 | require 'upwork/api/version' 17 | require 'upwork/api/logger' 18 | require 'upwork/api/config' 19 | require 'upwork/api/client' 20 | 21 | module Upwork # :nodoc: 22 | module Api 23 | # define some constants 24 | BASE_HOST = 'https://www.upwork.com' 25 | DEFAULT_EPOINT = 'api' 26 | 27 | $LOG = Logger.new 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/upwork/api/logger.rb: -------------------------------------------------------------------------------- 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 | # Logger for debug process 17 | class Logger 18 | # Print information string and dump parameter if any 19 | # 20 | # Arguments: 21 | # str: (String) 22 | # param: (Mixed) 23 | def i(str, param = nil) 24 | if $DEBUG 25 | puts "> #{str}" 26 | if param 27 | puts "<< dump-begin >>" 28 | p param 29 | puts "<< dump-end >>" 30 | end 31 | end 32 | end 33 | end 34 | end 35 | end -------------------------------------------------------------------------------- /upwork-api.gemspec: -------------------------------------------------------------------------------- 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 = "upwork-api" 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.} 12 | spec.description = %q{Ruby bindings for Upwork API 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 'oauth', '~> 0.4', '>= 0.4.7' 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", '~> 2.2', '>= 2.2.10' 24 | spec.add_development_dependency "rake" 25 | spec.add_development_dependency "mocha" 26 | spec.add_development_dependency "test-unit" 27 | end 28 | -------------------------------------------------------------------------------- /test/test_reports_finance_billings.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/reports/finance/billings' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class ReportsFinanceBillingsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_by_freelancer 13 | api = Upwork::Api::Routers::Reports::Finance::Billings.new(get_client_mock) 14 | assert api.get_by_freelancer('12', {}) 15 | end 16 | 17 | def test_get_by_freelancers_team 18 | api = Upwork::Api::Routers::Reports::Finance::Billings.new(get_client_mock) 19 | assert api.get_by_freelancers_team('12', {}) 20 | end 21 | 22 | def test_get_by_freelancers_company 23 | api = Upwork::Api::Routers::Reports::Finance::Billings.new(get_client_mock) 24 | assert api.get_by_freelancers_company('12', {}) 25 | end 26 | 27 | def test_get_by_buyers_team 28 | api = Upwork::Api::Routers::Reports::Finance::Billings.new(get_client_mock) 29 | assert api.get_by_buyers_team('12', {}) 30 | end 31 | 32 | def test_get_by_buyers_company 33 | api = Upwork::Api::Routers::Reports::Finance::Billings.new(get_client_mock) 34 | assert api.get_by_buyers_company('12', {}) 35 | end 36 | end -------------------------------------------------------------------------------- /test/test_reports_finance_earnings.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/reports/finance/earnings' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class ReportsFinanceEarningsTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_by_freelancer 13 | api = Upwork::Api::Routers::Reports::Finance::Earnings.new(get_client_mock) 14 | assert api.get_by_freelancer('12', {}) 15 | end 16 | 17 | def test_get_by_freelancers_team 18 | api = Upwork::Api::Routers::Reports::Finance::Earnings.new(get_client_mock) 19 | assert api.get_by_freelancers_team('12', {}) 20 | end 21 | 22 | def test_get_by_freelancers_company 23 | api = Upwork::Api::Routers::Reports::Finance::Earnings.new(get_client_mock) 24 | assert api.get_by_freelancers_company('12', {}) 25 | end 26 | 27 | def test_get_by_buyers_team 28 | api = Upwork::Api::Routers::Reports::Finance::Earnings.new(get_client_mock) 29 | assert api.get_by_buyers_team('12', {}) 30 | end 31 | 32 | def test_get_by_buyers_company 33 | api = Upwork::Api::Routers::Reports::Finance::Earnings.new(get_client_mock) 34 | assert api.get_by_buyers_company('12', {}) 35 | end 36 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/auth.rb: -------------------------------------------------------------------------------- 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 | # Get My Info 18 | class Auth 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 info of authenticated user 31 | def get_user_info 32 | $LOG.i "running " + __method__.to_s 33 | @client.get '/auth/v1/info' 34 | end 35 | end 36 | end 37 | end 38 | end -------------------------------------------------------------------------------- /test/test_metadata.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/metadata' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class MetadataTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_tests 13 | api = Upwork::Api::Routers::Metadata.new(get_client_mock) 14 | assert api.get_tests 15 | end 16 | 17 | def test_get_regions 18 | api = Upwork::Api::Routers::Metadata.new(get_client_mock) 19 | assert api.get_regions 20 | end 21 | 22 | def test_get_skills 23 | api = Upwork::Api::Routers::Metadata.new(get_client_mock) 24 | assert api.get_skills 25 | end 26 | 27 | def test_get_skills_v2 28 | api = Upwork::Api::Routers::Metadata.new(get_client_mock) 29 | assert api.get_skills_v2({}) 30 | end 31 | 32 | def test_get_specialties 33 | api = Upwork::Api::Routers::Metadata.new(get_client_mock) 34 | assert api.get_specialties 35 | end 36 | 37 | def test_get_categories_v2 38 | api = Upwork::Api::Routers::Metadata.new(get_client_mock) 39 | assert api.get_categories_v2 40 | end 41 | 42 | def test_get_reasons 43 | api = Upwork::Api::Routers::Metadata.new(get_client_mock) 44 | assert api.get_reasons({}) 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /test/test_hr_milestones.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/hr/milestones' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class HrMilestonesTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_active_milestone 13 | api = Upwork::Api::Routers::Hr::Milestones.new(get_client_mock) 14 | assert api.get_active_milestone('1234') 15 | end 16 | 17 | def test_get_submissions 18 | api = Upwork::Api::Routers::Hr::Milestones.new(get_client_mock) 19 | assert api.get_submissions('1234') 20 | end 21 | 22 | def test_create 23 | api = Upwork::Api::Routers::Hr::Milestones.new(get_client_mock) 24 | assert api.create({}) 25 | end 26 | 27 | def test_edit 28 | api = Upwork::Api::Routers::Hr::Milestones.new(get_client_mock) 29 | assert api.edit('1234', {}) 30 | end 31 | 32 | def test_activate 33 | api = Upwork::Api::Routers::Hr::Milestones.new(get_client_mock) 34 | assert api.activate('1234', {}) 35 | end 36 | 37 | def test_approve 38 | api = Upwork::Api::Routers::Hr::Milestones.new(get_client_mock) 39 | assert api.approve('1234', {}) 40 | end 41 | 42 | def test_delete 43 | api = Upwork::Api::Routers::Hr::Milestones.new(get_client_mock) 44 | assert api.delete('1234') 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /test/test_reports_time.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/reports/time' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class ReportsTimeTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_by_team_full 13 | api = Upwork::Api::Routers::Reports::Time.new(get_client_mock) 14 | assert api.get_by_team_full('company', 'team', {}) 15 | end 16 | 17 | def test_get_by_team_limited 18 | api = Upwork::Api::Routers::Reports::Time.new(get_client_mock) 19 | assert api.get_by_team_limited('company', 'team', {}) 20 | end 21 | 22 | def test_get_by_agency 23 | api = Upwork::Api::Routers::Reports::Time.new(get_client_mock) 24 | assert api.get_by_agency('company', 'agency', {}) 25 | end 26 | 27 | def test_get_by_company 28 | api = Upwork::Api::Routers::Reports::Time.new(get_client_mock) 29 | assert api.get_by_company('company', {}) 30 | end 31 | 32 | def test_get_by_freelancer_limited 33 | api = Upwork::Api::Routers::Reports::Time.new(get_client_mock) 34 | assert api.get_by_freelancer_limited('freelancer_id', {}) 35 | end 36 | 37 | def test_get_by_freelancer_full 38 | api = Upwork::Api::Routers::Reports::Time.new(get_client_mock) 39 | assert api.get_by_freelancer_full('freelancer_id', {}) 40 | end 41 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/jobs/search.rb: -------------------------------------------------------------------------------- 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 | module Jobs 18 | # Search Job profiles 19 | class Search 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Search profiles 32 | # 33 | # Arguments: 34 | # params: (Hash) 35 | def find(params) 36 | $LOG.i "running " + __method__.to_s 37 | @client.get '/profiles/v2/search/jobs', params 38 | end 39 | end 40 | end 41 | end 42 | end 43 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/payments.rb: -------------------------------------------------------------------------------- 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 | # Custom Payments 18 | class Payments 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 | # Submit bonus 31 | # 32 | # Arguments: 33 | # team_reference: (String) 34 | # params: (Hash) 35 | def submit_bonus(team_reference, params) 36 | $LOG.i "running " + __method__.to_s 37 | @client.post '/hr/v2/teams/' + team_reference + '/adjustments', params 38 | end 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/jobs/profile.rb: -------------------------------------------------------------------------------- 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 | module Jobs 18 | # Freelancer's profile info 19 | class Profile 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Get specific profile 32 | # 33 | # Arguments: 34 | # key: (String) 35 | def get_specific(key) 36 | $LOG.i "running " + __method__.to_s 37 | @client.get '/profiles/v1/jobs/' + key 38 | end 39 | end 40 | end 41 | end 42 | end 43 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/freelancers/search.rb: -------------------------------------------------------------------------------- 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 | module Freelancers 18 | # Search Freelancer's profiles 19 | class Search 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Search profiles 32 | # 33 | # Arguments: 34 | # params: (Hash) 35 | def find(params) 36 | $LOG.i "running " + __method__.to_s 37 | @client.get '/profiles/v2/search/providers', params 38 | end 39 | end 40 | end 41 | end 42 | end 43 | end -------------------------------------------------------------------------------- /test/test_client.rb: -------------------------------------------------------------------------------- 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 | 'consumer_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 17 | 'consumer_secret' => 'xxxxxxxxxxxxxxxx', 18 | 'access_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 19 | 'access_secret' => 'xxxxxxxxxxxxxxxx', 20 | 'debug' => false 21 | }) 22 | 23 | client = Upwork::Api::Client.new(config) 24 | client.epoint = 'gds' 25 | 26 | assert_equal 'https://www.upwork.com/services/api/auth',client.url_auth 27 | assert_equal 'https://www.upwork.com/api/auth/v1/oauth/token/request.json',client.url_rtoken 28 | assert_equal 'https://www.upwork.com/api/auth/v1/oauth/token/access.json',client.url_atoken 29 | assert_equal 'gds',client.epoint 30 | end 31 | 32 | def test_get 33 | assert get_client_mock.get('/some/api/url') 34 | end 35 | 36 | def test_post 37 | assert get_client_mock.post('/some/api/url', {}) 38 | end 39 | 40 | def test_put 41 | assert get_client_mock.put('/some/api/url', {}) 42 | end 43 | 44 | def test_delete 45 | assert get_client_mock.delete('/some/api/url', {}) 46 | end 47 | end -------------------------------------------------------------------------------- /lib/upwork/api/config.rb: -------------------------------------------------------------------------------- 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 | # Config storage 17 | class Config 18 | @@debug = false; 19 | 20 | attr_accessor :access_token, :access_secret 21 | attr_reader :consumer_key, :consumer_secret, :signature_method 22 | 23 | # Init config object 24 | # 25 | # Arguments: 26 | # config: (Hash) 27 | def initialize(config = {}) 28 | @consumer_key, @consumer_secret = config['consumer_key'], config['consumer_secret'] 29 | @access_token, @access_secret = config['access_token'], config['access_secret'] 30 | @signature_method = config['signature_method'] 31 | @@debug = config['debug'] 32 | 33 | $DEBUG = self.debug 34 | end 35 | 36 | # Get debug status 37 | def debug # :nodoc: 38 | @@debug 39 | end 40 | end 41 | end 42 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/interviews.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | # Interviews workflow 19 | class Interviews 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Invite to Interview 32 | # 33 | # Arguments: 34 | # job_key: (String) 35 | # params: (Hash) 36 | def invite(job_key, params) 37 | $LOG.i "running " + __method__.to_s 38 | @client.post '/hr/v1/jobs/' + job_key + '/candidates', params 39 | end 40 | end 41 | end 42 | end 43 | end 44 | end -------------------------------------------------------------------------------- /test/test_activities_team.rb: -------------------------------------------------------------------------------- 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 47 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/roles.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | # Roles 19 | class Roles 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Get user roles 32 | def get_all 33 | $LOG.i "running " + __method__.to_s 34 | @client.get '/hr/v2/userroles' 35 | end 36 | 37 | # Get by specific user 38 | # 39 | # Arguments: 40 | # reference: (String) 41 | def get_by_specific_user(user_reference) 42 | $LOG.i "running " + __method__.to_s 43 | @client.get '/hr/v2/userroles/' + user_reference 44 | end 45 | end 46 | end 47 | end 48 | end 49 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/organization/teams.rb: -------------------------------------------------------------------------------- 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 | module Organization 18 | # Teams inside Organization 19 | class Teams 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Get Teams info 32 | def get_list 33 | $LOG.i "running " + __method__.to_s 34 | @client.get '/hr/v2/teams' 35 | end 36 | 37 | # Get Users in Team 38 | # 39 | # Arguments: 40 | # team_reference: (String) 41 | def get_users_in_team(team_reference) 42 | $LOG.i "running " + __method__.to_s 43 | @client.get '/hr/v2/teams/' + team_reference + '/users' 44 | end 45 | end 46 | end 47 | end 48 | end 49 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/organization/users.rb: -------------------------------------------------------------------------------- 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 | module Organization 18 | # Users inside Organization 19 | class Users 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Get Auth User Info 32 | def get_my_info 33 | $LOG.i "running " + __method__.to_s 34 | @client.get '/hr/v2/users/me' 35 | end 36 | 37 | # Get Specific User Info 38 | # 39 | # Arguments: 40 | # user_reference: (String) 41 | def get_specific(user_reference) 42 | $LOG.i "running " + __method__.to_s 43 | @client.get '/hr/v2/users/' + user_reference 44 | end 45 | end 46 | end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/engagements.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | # Engagements API 19 | class Engagements 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Get list of engagements 32 | # 33 | # Arguments: 34 | # params: (Hash) 35 | def get_list(params) 36 | $LOG.i "running " + __method__.to_s 37 | @client.get '/hr/v2/engagements', params 38 | end 39 | 40 | # Get specific engagement 41 | # 42 | # Arguments: 43 | # reference: (String) 44 | def get_specific(reference) 45 | $LOG.i "running " + __method__.to_s 46 | @client.get '/hr/v2/engagements/' + reference 47 | end 48 | end 49 | end 50 | end 51 | end 52 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/freelancers/profile.rb: -------------------------------------------------------------------------------- 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 | module Freelancers 18 | # Freelancer's profile info 19 | class Profile 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Get specific profile 32 | # 33 | # Arguments: 34 | # key: (String) 35 | def get_specific(key) 36 | $LOG.i "running " + __method__.to_s 37 | @client.get '/profiles/v1/providers/' + key 38 | end 39 | 40 | # Get brief info on specific profile 41 | # 42 | # Arguments: 43 | # key: (String) 44 | def get_specific_brief(key) 45 | $LOG.i "running " + __method__.to_s 46 | @client.get '/profiles/v1/providers/' + key + '/brief' 47 | end 48 | end 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/workdiary.rb: -------------------------------------------------------------------------------- 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 Workdiary by Company 31 | # Arguments: 32 | # company: (String) 33 | # date: (String) 34 | # params: (Hash) 35 | def get(company, date, params = {}) 36 | $LOG.i "running " + __method__.to_s 37 | @client.get '/team/v3/workdiaries/companies/' + company + '/' + date, params 38 | end 39 | 40 | # Get Work Diary by Contract 41 | # Arguments: 42 | # contract: (String) 43 | # date: (String) 44 | # params: (Hash) 45 | def get_by_contract(contract, date, params = {}) 46 | $LOG.i "running " + __method__.to_s 47 | @client.get '/team/v3/workdiaries/contracts/' + contract + '/' + date, params 48 | end 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /example/myapp.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | $:.unshift '../lib' 4 | 5 | $LOAD_PATH << File.dirname(__FILE__) 6 | 7 | require 'upwork/api' 8 | require 'upwork/api/routers/auth' 9 | require 'upwork/api/routers/reports/time' 10 | require 'upwork/api/routers/freelancers/search' 11 | #require 'pry' 12 | 13 | # initiate config 14 | config = Upwork::Api::Config.new({ 15 | 'consumer_key' => 'xxxxxxxx', 16 | 'consumer_secret' => 'xxxxxxxx', 17 | 'access_token' => 'xxxxxxxx',# assign if known 18 | 'access_secret' => 'xxxxxxxx',# assign if known 19 | #'debug' => false 20 | }) 21 | 22 | # setup client 23 | client = Upwork::Api::Client.new(config) 24 | 25 | # run authorization in case we haven't done it yet 26 | # and do not have an access token-secret pair 27 | if !config.access_token and !config.access_secret 28 | authz_url = client.get_authorization_url 29 | # for web-based applications you need to specify the exact oauth_callback explicitly 30 | # authz_url = client.get_authorization_url "https://my-callback-url-here.com" 31 | 32 | puts "Visit the authorization url and provide oauth_verifier for further authorization" 33 | puts authz_url 34 | verifier = gets.strip 35 | @token = client.get_access_token(verifier) 36 | # store access token data in safe place! 37 | end 38 | 39 | # get my auth data 40 | auth = Upwork::Api::Routers::Auth.new(client) 41 | info = auth.get_user_info 42 | 43 | report = Upwork::Api::Routers::Reports::Time.new(client) 44 | report_response = report.get_by_freelancer_limited('mnovozhilov', {'tqx' => 'out:json', 'tq' => "select task where worked_on >= '2014-06-01' AND worked_on <= '2014-06-03' order by worked_on"}) 45 | 46 | p info['info']['portrait_32_img'], report_response 47 | 48 | params = {'q' => 'python'} 49 | freelancers = Upwork::Api::Routers::Freelancers::Search.new(client) 50 | p freelancers.find(params) 51 | 52 | # Start REPL session 53 | #binding.pry 54 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/freelancers/applications.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | module Freelancers 19 | # Freelancer Job Applications API 20 | class Applications 21 | ENTRY_POINT = 'api' 22 | 23 | # Init 24 | # 25 | # Arguments: 26 | # client: (Client) 27 | def initialize(client) 28 | @client = client 29 | @client.epoint = ENTRY_POINT 30 | end 31 | 32 | # Get list of applications 33 | # 34 | # Arguments: 35 | # params: (Hash) 36 | def get_list(params = {}) 37 | $LOG.i "running " + __method__.to_s 38 | @client.get '/hr/v4/contractors/applications', params 39 | end 40 | 41 | # Get specific application 42 | # 43 | # Arguments: 44 | # reference: (String) 45 | def get_specific(reference) 46 | $LOG.i "running " + __method__.to_s 47 | @client.get '/hr/v4/contractors/applications/' + reference 48 | end 49 | end 50 | end 51 | end 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/clients/applications.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | module Clients 19 | # Client Job Applications API 20 | class Applications 21 | ENTRY_POINT = 'api' 22 | 23 | # Init 24 | # 25 | # Arguments: 26 | # client: (Client) 27 | def initialize(client) 28 | @client = client 29 | @client.epoint = ENTRY_POINT 30 | end 31 | 32 | # Get list of applications 33 | # 34 | # Arguments: 35 | # params: (Hash) 36 | def get_list(params) 37 | $LOG.i "running " + __method__.to_s 38 | @client.get '/hr/v4/clients/applications', params 39 | end 40 | 41 | # Get specific application 42 | # 43 | # Arguments: 44 | # reference: (String) 45 | # params: (Hash) 46 | def get_specific(reference, params) 47 | $LOG.i "running " + __method__.to_s 48 | @client.get '/hr/v4/clients/applications/' + reference, params 49 | end 50 | end 51 | end 52 | end 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/workdays.rb: -------------------------------------------------------------------------------- 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/v3/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/v3/workdays/contracts/' + contract + '/' + from_date + ',' + till_date, params 50 | end 51 | end 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/reports/finance/accounts.rb: -------------------------------------------------------------------------------- 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 | module Reports 18 | module Finance 19 | # Generate Financial Reports for Accounts 20 | class Accounts 21 | ENTRY_POINT = 'gds' 22 | 23 | # Init 24 | # 25 | # Arguments: 26 | # client: (Client) 27 | def initialize(client) 28 | @client = client 29 | @client.epoint = ENTRY_POINT 30 | end 31 | 32 | # Generate Financial Reports for an owned Account 33 | # 34 | # Arguments: 35 | # freelancer_reference: (String) 36 | # params: (Hash) 37 | def get_owned(freelancer_reference, params) 38 | $LOG.i "running " + __method__.to_s 39 | @client.get '/finreports/v2/financial_account_owner/' + freelancer_reference, params 40 | end 41 | 42 | # Generate Financial Reports for a Specific Account 43 | # 44 | # Arguments: 45 | # entity_reference: (String) 46 | # params: (Hash) 47 | def get_specific(entity_reference, params) 48 | $LOG.i "running " + __method__.to_s 49 | @client.get '/finreports/v2/financial_accounts/' + entity_reference, params 50 | end 51 | end 52 | end 53 | end 54 | end 55 | end 56 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/snapshot.rb: -------------------------------------------------------------------------------- 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/v3/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/v3/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/v3/snapshots/contracts/' + contract + '/' + ts 58 | end 59 | end 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /test/test_messages.rb: -------------------------------------------------------------------------------- 1 | $:.unshift 'lib' 2 | $LOAD_PATH << File.dirname(__FILE__) 3 | 4 | require 'helper' 5 | require 'upwork/api/routers/messages' 6 | require 'test/unit' 7 | require 'mocha/test_unit' 8 | 9 | class MessagesTest < Test::Unit::TestCase 10 | include TestHelper 11 | 12 | def test_get_rooms 13 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 14 | assert api.get_rooms('company') 15 | end 16 | 17 | def test_get_room_details 18 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 19 | assert api.get_room_details('company', 'room-id', {}) 20 | end 21 | 22 | def test_get_room_messages 23 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 24 | assert api.get_room_messages('company', 'room-id', {}) 25 | end 26 | 27 | def test_get_room_by_offer 28 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 29 | assert api.get_room_by_offer('company', '1234', {}) 30 | end 31 | 32 | def test_get_room_by_application 33 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 34 | assert api.get_room_by_application('company', '1234', {}) 35 | end 36 | 37 | def test_get_room_by_contract 38 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 39 | assert api.get_room_by_contract('company', '1234', {}) 40 | end 41 | 42 | def test_create_room 43 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 44 | assert api.create_room('company', {}) 45 | end 46 | 47 | def test_send_message_to_room 48 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 49 | assert api.send_message_to_room('company', 'room-id', {}) 50 | end 51 | 52 | def test_send_message_to_rooms 53 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 54 | assert api.send_message_to_rooms('company', {}) 55 | end 56 | 57 | def test_update_room_settings 58 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 59 | assert api.update_room_settings('company', 'room-id', 'username', {}) 60 | end 61 | 62 | def test_update_room_metadata 63 | api = Upwork::Api::Routers::Messages.new(get_client_mock) 64 | assert api.update_room_metadata('company', 'room-id', {}) 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/clients/offers.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | module Clients 19 | # Client Job Offers API 20 | class Offers 21 | ENTRY_POINT = 'api' 22 | 23 | # Init 24 | # 25 | # Arguments: 26 | # client: (Client) 27 | def initialize(client) 28 | @client = client 29 | @client.epoint = ENTRY_POINT 30 | end 31 | 32 | # Get list of offers 33 | # 34 | # Arguments: 35 | # params: (Hash) 36 | def get_list(params) 37 | $LOG.i "running " + __method__.to_s 38 | @client.get '/offers/v1/clients/offers', params 39 | end 40 | 41 | # Get specific offer 42 | # 43 | # Arguments: 44 | # reference: (String) 45 | # params: (Hash) 46 | def get_specific(reference, params) 47 | $LOG.i "running " + __method__.to_s 48 | @client.get '/offers/v1/clients/offers/' + reference, params 49 | end 50 | 51 | # Make an Offer 52 | # 53 | # Arguments: 54 | # params: (Hash) 55 | def make_offer(params) 56 | $LOG.i "running " + __method__.to_s 57 | @client.post '/offers/v1/clients/offers', params 58 | end 59 | end 60 | end 61 | end 62 | end 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/contracts.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | # Contracts API 19 | class Contracts 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Suspend Contract 32 | # 33 | # Arguments: 34 | # reference: (String) 35 | # params: (Hash) 36 | def suspend_contract(reference, params) 37 | $LOG.i "running " + __method__.to_s 38 | @client.put '/hr/v2/contracts/' + reference + '/suspend', params 39 | end 40 | 41 | # Restart Contract 42 | # 43 | # Arguments: 44 | # reference: (String) 45 | # params: (Hash) 46 | def restart_contract(reference, params) 47 | $LOG.i "running " + __method__.to_s 48 | @client.put '/hr/v2/contracts/' + reference + '/restart', params 49 | end 50 | 51 | # End Contract 52 | # 53 | # Arguments: 54 | # reference: (String) 55 | # params: (Hash) 56 | def end_contract(reference, params) 57 | $LOG.i "running " + __method__.to_s 58 | @client.delete '/hr/v2/contracts/' + reference, params 59 | end 60 | end 61 | end 62 | end 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/submissions.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | # Submissions workflow 19 | class Submissions 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Freelancer submits work for the client to approve 32 | # 33 | # Arguments: 34 | # params: (Hash) 35 | def request_approval(params) 36 | $LOG.i "running " + __method__.to_s 37 | @client.post '/hr/v3/fp/submissions', params 38 | end 39 | 40 | # Approve an existing Submission 41 | # 42 | # Arguments: 43 | # submission_id: (String) 44 | # params: (Hash) 45 | def approve(submission_id, params) 46 | $LOG.i "running " + __method__.to_s 47 | @client.put '/hr/v3/fp/submissions/' + submission_id + '/approve', params 48 | end 49 | 50 | # Reject an existing Submission 51 | # 52 | # Arguments: 53 | # submission_id: (String) 54 | # params: (Hash) 55 | def reject(submission_id, params) 56 | $LOG.i "running " + __method__.to_s 57 | @client.put '/hr/v3/fp/submissions/' + submission_id + '/reject', params 58 | end 59 | end 60 | end 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/freelancers/offers.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | module Freelancers 19 | # Freelancers Job Offers API 20 | class Offers 21 | ENTRY_POINT = 'api' 22 | 23 | # Init 24 | # 25 | # Arguments: 26 | # client: (Client) 27 | def initialize(client) 28 | @client = client 29 | @client.epoint = ENTRY_POINT 30 | end 31 | 32 | # Get list of offers 33 | # 34 | # Arguments: 35 | # params: (Hash) 36 | def get_list(params = {}) 37 | $LOG.i "running " + __method__.to_s 38 | @client.get '/offers/v1/contractors/offers', params 39 | end 40 | 41 | # Get specific offer 42 | # 43 | # Arguments: 44 | # reference: (String) 45 | def get_specific(reference) 46 | $LOG.i "running " + __method__.to_s 47 | @client.get '/offers/v1/contractors/offers/' + reference 48 | end 49 | 50 | # Apply specific action 51 | # 52 | # Arguments: 53 | # reference: (String) 54 | # params: (Hash) 55 | def actions(reference, params) 56 | $LOG.i "running " + __method__.to_s 57 | @client.post '/offers/v1/contractors/actions/' + reference, params 58 | end 59 | end 60 | end 61 | end 62 | end 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/activities/engagement.rb: -------------------------------------------------------------------------------- 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 | module Activities 18 | # Engagement Activities 19 | class Engagement 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # List activities for specific engagement 32 | # 33 | # Arguments: 34 | # engagement_ref: (String) 35 | def get_specific(engagement_ref) 36 | @client.get '/tasks/v2/tasks/contracts/' + engagement_ref 37 | end 38 | 39 | # Assign engagements to the list of activities 40 | # 41 | # Arguments: 42 | # company: (String) 43 | # team: (String) 44 | # engagement: (String) 45 | # params: (Hash) 46 | def assign(company, team, engagement, params) 47 | @client.put '/otask/v1/tasks/companies/' + company + '/teams/' + team + '/engagements/' + engagement + '/tasks', params 48 | end 49 | 50 | # Assign to specific engagement the list of activities 51 | # 52 | # Arguments: 53 | # engagement_ref: (String) 54 | # params: (Hash) 55 | def assign_to_engagement(engagement_ref, params) 56 | @client.put '/tasks/v2/tasks/contracts/' + engagement_ref, params 57 | end 58 | 59 | end 60 | end 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/organization/companies.rb: -------------------------------------------------------------------------------- 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 | module Organization 18 | # Companies inside Organization 19 | class Companies 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Get Companies Info 32 | def get_list 33 | $LOG.i "running " + __method__.to_s 34 | @client.get '/hr/v2/companies' 35 | end 36 | 37 | # Get Specific Company 38 | # 39 | # Arguments: 40 | # company_reference: (String) 41 | def get_specific(company_reference) 42 | $LOG.i "running " + __method__.to_s 43 | @client.get '/hr/v2/companies/' + company_reference 44 | end 45 | 46 | # Get Teams in Company 47 | # 48 | # Arguments: 49 | # company_reference: (String) 50 | def get_teams(company_reference) 51 | $LOG.i "running " + __method__.to_s 52 | @client.get '/hr/v2/companies/' + company_reference + '/teams' 53 | end 54 | 55 | # Get Users in Company 56 | # 57 | # Arguments: 58 | # company_reference: (String) 59 | def get_users(company_reference) 60 | $LOG.i "running " + __method__.to_s 61 | @client.get '/hr/v2/companies/' + company_reference + '/users' 62 | end 63 | end 64 | end 65 | end 66 | end 67 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ruby bindings for Upwork API (OAuth1) - DEPRECATED 2 | ============ 3 | 4 | [![License](https://img.shields.io/github/license/upwork/ruby-upwork)](http://www.apache.org/licenses/LICENSE-2.0.html) 5 | [![Gem Version](https://badge.fury.io/rb/upwork-api.svg)](http://badge.fury.io/rb/upwork-api) 6 | [![GitHub release](https://img.shields.io/github/release/upwork/ruby-upwork.svg)](https://github.com/upwork/ruby-upwork/releases) 7 | [![Build Status](https://github.com/upwork/ruby-upwork/workflows/build/badge.svg)](https://github.com/upwork/ruby-upwork/actions) 8 | 9 | # Upwork::Api 10 | 11 | This project provides a set of resources of Upwork API from http://developers.upwork.com 12 | based on OAuth 1.0a. 13 | 14 | # Features 15 | These are the supported API resources: 16 | 17 | * My Info 18 | * Custom Payments 19 | * Hiring 20 | * Job and Freelancer Profile 21 | * Search Jobs and Freelancers 22 | * Organization 23 | * Messages 24 | * Time and Financial Reporting 25 | * Metadata 26 | * Snapshot 27 | * Team 28 | * Workd Diary 29 | * Activities 30 | 31 | # License 32 | 33 | Copyright 2015 Upwork Corporation. All Rights Reserved. 34 | 35 | ruby-upwork is licensed under the Apache License, Version 2.0 (the "License"); 36 | you may not use this file except in compliance with the License. 37 | You may obtain a copy of the License at 38 | 39 | http://www.apache.org/licenses/LICENSE-2.0 40 | 41 | Unless required by applicable law or agreed to in writing, software 42 | distributed under the License is distributed on an "AS IS" BASIS, 43 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 44 | See the License for the specific language governing permissions and 45 | limitations under the License. 46 | 47 | ## SLA 48 | The usage of this API is ruled by the Terms of Use at: 49 | 50 | https://developers.upwork.com/api-tos.html 51 | 52 | # Application Integration 53 | To integrate this library you need to have: 54 | 55 | * Ruby >= 1.9.3 56 | * OAuth Extension installed (use `gem install oauth`) 57 | 58 | ## Installation 59 | 60 | Add this line to your application's Gemfile: 61 | 62 | gem 'upwork-api' 63 | 64 | And then execute: 65 | 66 | $ bundle 67 | 68 | Or install it yourself as: 69 | 70 | $ gem install upwork-api 71 | 72 | ## Usage 73 | 74 | 1. 75 | Follow instructions from the `Installation` section. 76 | 77 | 2. 78 | Open `myapp.rb` and type the `consumer_key` and `consumer_secret` that you previously got from the API Center. 79 | ***That's all. Run your app as `ruby myapp.rb` and have fun.***' 80 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/metadata.rb: -------------------------------------------------------------------------------- 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 | # Get Metadata 18 | class Metadata 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 categories (v2) 31 | def get_categories_v2 32 | $LOG.i "running " + __method__.to_s 33 | @client.get '/profiles/v2/metadata/categories' 34 | end 35 | 36 | # Get skills 37 | def get_skills 38 | $LOG.i "running " + __method__.to_s 39 | @client.get '/profiles/v1/metadata/skills' 40 | end 41 | 42 | # Get skills V2 43 | def get_skills_v2(params) 44 | $LOG.i "running " + __method__.to_s 45 | @client.get '/profiles/v2/metadata/skills', params 46 | end 47 | 48 | # Get specialties 49 | def get_specialties 50 | $LOG.i "running " + __method__.to_s 51 | @client.get '/profiles/v1/metadata/specialties' 52 | end 53 | 54 | # Get regions 55 | def get_regions 56 | $LOG.i "running " + __method__.to_s 57 | @client.get '/profiles/v1/metadata/regions' 58 | end 59 | 60 | # Get tests 61 | def get_tests 62 | $LOG.i "running " + __method__.to_s 63 | @client.get '/profiles/v1/metadata/tests' 64 | end 65 | 66 | # Get reasons 67 | # 68 | # Arguments: 69 | # params: (Hash) 70 | def get_reasons(params) 71 | $LOG.i "running " + __method__.to_s 72 | @client.get '/profiles/v1/metadata/reasons', params; 73 | end 74 | end 75 | end 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/jobs.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | # Jobs API 19 | class Jobs 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Get list of jobs 32 | # 33 | # Arguments: 34 | # params: (Hash) 35 | def get_list(params) 36 | $LOG.i "running " + __method__.to_s 37 | @client.get '/hr/v2/jobs', params 38 | end 39 | 40 | # Get specific job by key 41 | # 42 | # Arguments: 43 | # key: (String) 44 | def get_specific(key) 45 | $LOG.i "running " + __method__.to_s 46 | @client.get '/hr/v2/jobs/' + key 47 | end 48 | 49 | # Post a new job 50 | # 51 | # Arguments: 52 | # params: (Hash) 53 | def post_job(params) 54 | $LOG.i "running " + __method__.to_s 55 | @client.post '/hr/v2/jobs', params 56 | end 57 | 58 | # Edit existent job 59 | # 60 | # Arguments: 61 | # params: (Hash) 62 | def edit_job(key, params) 63 | $LOG.i "running " + __method__.to_s 64 | @client.put '/hr/v2/jobs/' + key, params 65 | end 66 | 67 | # Delete existent job 68 | # 69 | # Arguments: 70 | # params: (Hash) 71 | def delete_job(key, params) 72 | $LOG.i "running " + __method__.to_s 73 | @client.delete '/hr/v2/jobs/' + key, params 74 | end 75 | end 76 | end 77 | end 78 | end 79 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/reports/finance/billings.rb: -------------------------------------------------------------------------------- 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 | module Reports 18 | module Finance 19 | # Generate Billing Reports 20 | class Billings 21 | ENTRY_POINT = 'gds' 22 | 23 | # Init 24 | # 25 | # Arguments: 26 | # client: (Client) 27 | def initialize(client) 28 | @client = client 29 | @client.epoint = ENTRY_POINT 30 | end 31 | 32 | # Generate Billing Reports for a Specific Freelancer 33 | # 34 | # Arguments: 35 | # freelancer_reference: (String) 36 | # params: (Hash) 37 | def get_by_freelancer(freelancer_reference, params) 38 | $LOG.i "running " + __method__.to_s 39 | @client.get '/finreports/v2/providers/' + freelancer_reference + '/billings', params 40 | end 41 | 42 | # Generate Billing Reports for a Specific Freelancer's Team 43 | # 44 | # Arguments: 45 | # freelancer_team_reference: (String) 46 | # params: (Hash) 47 | def get_by_freelancers_team(freelancer_team_reference, params) 48 | $LOG.i "running " + __method__.to_s 49 | @client.get '/finreports/v2/provider_teams/' + freelancer_team_reference + '/billings', params 50 | end 51 | 52 | # Generate Billing Reports for a Specific Freelancer's Company 53 | # 54 | # Arguments: 55 | # freelancer_company_reference: (String) 56 | # params: (Hash) 57 | def get_by_freelancers_company(freelancer_company_reference, params) 58 | $LOG.i "running " + __method__.to_s 59 | @client.get '/finreports/v2/provider_companies/' + freelancer_company_reference + '/billings', params 60 | end 61 | 62 | # Generate Billing Reports for a Specific Buyer's Team 63 | # 64 | # Arguments: 65 | # buyer_team_reference: (String) 66 | # params: (Hash) 67 | def get_by_buyers_team(buyer_team_reference, params) 68 | $LOG.i "running " + __method__.to_s 69 | @client.get '/finreports/v2/buyer_teams/' + buyer_team_reference + '/billings', params 70 | end 71 | 72 | # Generate Billing Reports for a Specific Buyer's Company 73 | # 74 | # Arguments: 75 | # buyer_company_reference: (String) 76 | # params: (Hash) 77 | def get_by_buyers_company(buyer_company_reference, params) 78 | $LOG.i "running " + __method__.to_s 79 | @client.get '/finreports/v2/buyer_companies/' + buyer_company_reference + '/billings', params 80 | end 81 | end 82 | end 83 | end 84 | end 85 | end 86 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/reports/finance/earnings.rb: -------------------------------------------------------------------------------- 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 | module Reports 18 | module Finance 19 | # Generate Earning Reports 20 | class Earnings 21 | ENTRY_POINT = 'gds' 22 | 23 | # Init 24 | # 25 | # Arguments: 26 | # client: (Client) 27 | def initialize(client) 28 | @client = client 29 | @client.epoint = ENTRY_POINT 30 | end 31 | 32 | # Generate Earning Reports for a Specific Freelancer 33 | # 34 | # Arguments: 35 | # freelancer_reference: (String) 36 | # params: (Hash) 37 | def get_by_freelancer(freelancer_reference, params) 38 | $LOG.i "running " + __method__.to_s 39 | @client.get '/finreports/v2/providers/' + freelancer_reference + '/earnings', params 40 | end 41 | 42 | # Generate Earning Reports for a Specific Freelancer's Team 43 | # 44 | # Arguments: 45 | # freelancer_team_reference: (String) 46 | # params: (Hash) 47 | def get_by_freelancers_team(freelancer_team_reference, params) 48 | $LOG.i "running " + __method__.to_s 49 | @client.get '/finreports/v2/provider_teams/' + freelancer_team_reference + '/earnings', params 50 | end 51 | 52 | # Generate Earning Reports for a Specific Freelancer's Company 53 | # 54 | # Arguments: 55 | # freelancer_company_reference: (String) 56 | # params: (Hash) 57 | def get_by_freelancers_company(freelancer_company_reference, params) 58 | $LOG.i "running " + __method__.to_s 59 | @client.get '/finreports/v2/provider_companies/' + freelancer_company_reference + '/earnings', params 60 | end 61 | 62 | # Generate Earning Reports for a Specific Buyer's Team 63 | # 64 | # Arguments: 65 | # buyer_team_reference: (String) 66 | # params: (Hash) 67 | def get_by_buyers_team(buyer_team_reference, params) 68 | $LOG.i "running " + __method__.to_s 69 | @client.get '/finreports/v2/buyer_teams/' + buyer_team_reference + '/earnings', params 70 | end 71 | 72 | # Generate Earning Reports for a Specific Buyer's Company 73 | # 74 | # Arguments: 75 | # buyer_company_reference: (String) 76 | # params: (Hash) 77 | def get_by_buyers_company(buyer_company_reference, params) 78 | $LOG.i "running " + __method__.to_s 79 | @client.get '/finreports/v2/buyer_companies/' + buyer_company_reference + '/earnings', params 80 | end 81 | end 82 | end 83 | end 84 | end 85 | end 86 | end -------------------------------------------------------------------------------- /lib/upwork/api/routers/hr/milestones.rb: -------------------------------------------------------------------------------- 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 | module Hr 18 | # Milestones workflow 19 | class Milestones 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Get active Milestone for specific Contract 32 | # 33 | # Arguments: 34 | # contract_id: (String) 35 | def get_active_milestone(contract_id) 36 | $LOG.i "running " + __method__.to_s 37 | @client.get '/hr/v3/fp/milestones/statuses/active/contracts/' + contract_id 38 | end 39 | 40 | # Get active Milestone for specific Contract 41 | # 42 | # Arguments: 43 | # milestone_id: (String) 44 | def get_submissions(milestone_id) 45 | $LOG.i "running " + __method__.to_s 46 | @client.get '/hr/v3/fp/milestones/' + milestone_id + '/submissions' 47 | end 48 | 49 | # Create a new Milestone 50 | # 51 | # Arguments: 52 | # params: (Hash) 53 | def create(params) 54 | $LOG.i "running " + __method__.to_s 55 | @client.post '/hr/v3/fp/milestones', params 56 | end 57 | 58 | # Edit an existing Milestone 59 | # 60 | # Arguments: 61 | # milestone_id: (String) 62 | # params: (Hash) 63 | def edit(milestone_id, params) 64 | $LOG.i "running " + __method__.to_s 65 | @client.put '/hr/v3/fp/milestones/' + milestone_id, params 66 | end 67 | 68 | # Activate an existing Milestone 69 | # 70 | # Arguments: 71 | # milestone_id: (String) 72 | # params: (Hash) 73 | def activate(milestone_id, params) 74 | $LOG.i "running " + __method__.to_s 75 | @client.put '/hr/v3/fp/milestones/' + milestone_id + '/activate', params 76 | end 77 | 78 | # Approve an existing Milestone 79 | # 80 | # Arguments: 81 | # milestone_id: (String) 82 | # params: (Hash) 83 | def approve(milestone_id, params) 84 | $LOG.i "running " + __method__.to_s 85 | @client.put '/hr/v3/fp/milestones/' + milestone_id + '/approve', params 86 | end 87 | 88 | # Delete an existing Milestone 89 | # 90 | # Arguments: 91 | # milestone_id: (String) 92 | def delete(milestone_id) 93 | $LOG.i "running " + __method__.to_s 94 | @client.delete '/hr/v3/fp/milestones/' + milestone_id 95 | end 96 | end 97 | end 98 | end 99 | end 100 | end 101 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/activities/team.rb: -------------------------------------------------------------------------------- 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 | module Activities 18 | # Team Activities 19 | class Team 20 | ENTRY_POINT = 'api' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # List all oTask/Activity records within a team 32 | # 33 | # Arguments: 34 | # company: (String) 35 | # team: (String) 36 | def get_list(company, team) 37 | get_by_type company, team, nil 38 | end 39 | 40 | # List all oTask/Activity records within a Company by specified code(s) 41 | # 42 | # Arguments: 43 | # company: (String) 44 | # team: (String) 45 | # code: (String) 46 | def get_specific_list(company, team, code) 47 | get_by_type company, team, code 48 | end 49 | 50 | # Create an oTask/Activity record within a team 51 | # 52 | # Arguments: 53 | # company: (String) 54 | # team: (String) 55 | # params: (Hash) 56 | def add_activity(company, team, params) 57 | @client.post '/otask/v1/tasks/companies/' + company + '/teams/' + team + '/tasks', params 58 | end 59 | 60 | # Update specific oTask/Activity record within a team 61 | # 62 | # Arguments: 63 | # company: (String) 64 | # team: (String) 65 | # code: (String) 66 | # params: (Hash) 67 | def update_activities(company, team, code, params) 68 | @client.put '/otask/v1/tasks/companies/' + company + '/teams/' + team + '/tasks/' + code, params 69 | end 70 | 71 | # Archive specific oTask/Activity record within a team 72 | # 73 | # Arguments: 74 | # company: (String) 75 | # team: (String) 76 | # code: (String) 77 | def archive_activities(company, team, code) 78 | @client.put '/otask/v1/tasks/companies/' + company + '/teams/' + team + '/archive/' + code 79 | end 80 | 81 | # Unarchive specific oTask/Activity record within a team 82 | # 83 | # Arguments: 84 | # company: (String) 85 | # team: (String) 86 | # code: (String) 87 | def unarchive_activities(company, team, code) 88 | @client.put '/otask/v1/tasks/companies/' + company + '/teams/' + team + '/unarchive/' + code 89 | end 90 | 91 | # Update a group of oTask/Activity records within a company 92 | # 93 | # Arguments: 94 | # company: (String) 95 | # params: (Hash) 96 | def update_batch(company, params) 97 | @client.put '/otask/v1/tasks/companies/' + company + '/tasks/batch', params 98 | end 99 | 100 | private 101 | 102 | # Get by type 103 | def get_by_type(company, team, code = nil) 104 | $LOG.i "running " + __method__.to_s 105 | url = ''; 106 | if code != nil 107 | url = '/' + code; 108 | end 109 | 110 | @client.get '/otask/v1/tasks/companies/' + company + '/teams/' + team + '/tasks' + url 111 | end 112 | 113 | end 114 | end 115 | end 116 | end 117 | end 118 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/reports/time.rb: -------------------------------------------------------------------------------- 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 | module Reports 18 | # Time reports 19 | class Time 20 | ENTRY_POINT = 'gds' 21 | 22 | # Init 23 | # 24 | # Arguments: 25 | # client: (Client) 26 | def initialize(client) 27 | @client = client 28 | @client.epoint = ENTRY_POINT 29 | end 30 | 31 | # Generate Time Reports for a Specific Team (with financial info) 32 | # 33 | # Arguments: 34 | # company: (String) 35 | # team: (String) 36 | # params: (Hash) 37 | def get_by_team_full(company, team, params) 38 | $LOG.i "running " + __method__.to_s 39 | get_by_type(company, team, nil, params, false) 40 | end 41 | 42 | # Generate Time Reports for a Specific Team (hide financial info) 43 | # 44 | # Arguments: 45 | # company: (String) 46 | # team: (String) 47 | # params: (Hash) 48 | def get_by_team_limited(company, team, params) 49 | $LOG.i "running " + __method__.to_s 50 | get_by_type(company, team, nil, params, true) 51 | end 52 | 53 | # Generating Agency Specific Reports 54 | # 55 | # Arguments: 56 | # company: (String) 57 | # agency: (String) 58 | # params: (Hash) 59 | def get_by_agency(company, agency, params) 60 | $LOG.i "running " + __method__.to_s 61 | get_by_type(company, nil, agency, params, false) 62 | end 63 | 64 | # Generating Company Wide Reports 65 | # 66 | # Arguments: 67 | # company: (String) 68 | # params: (Hash) 69 | def get_by_company(company, params) 70 | $LOG.i "running " + __method__.to_s 71 | get_by_type(company, nil, nil, params, false) 72 | end 73 | 74 | # Generating Freelancer's Specific Reports (hide financial info) 75 | # 76 | # Arguments: 77 | # freelancer_id: (String) 78 | # params: (Hash) 79 | def get_by_freelancer_limited(freelancer_id, params) 80 | $LOG.i "running " + __method__.to_s 81 | @client.get '/timereports/v1/providers/' + freelancer_id + '/hours', params 82 | end 83 | 84 | # Generating Freelancer's Specific Reports (with financial info) 85 | # 86 | # Arguments: 87 | # freelancer_id: (String) 88 | # params: (Hash) 89 | def get_by_freelancer_full(freelancer_id, params) 90 | $LOG.i "running " + __method__.to_s 91 | @client.get '/timereports/v1/providers/' + freelancer_id, params 92 | end 93 | 94 | private 95 | 96 | def get_by_type(company, team, agency, params, hide_fin_data) 97 | $LOG.i "running " + __method__.to_s 98 | url = ''; 99 | if (team != nil) 100 | url = '/teams/' + team; 101 | if (hide_fin_data) 102 | url = url + '/hours'; 103 | end 104 | elsif (agency != nil) 105 | url = '/agencies/' + agency 106 | end 107 | 108 | @client.get '/timereports/v1/companies/' + company + url, params 109 | end 110 | end 111 | end 112 | end 113 | end 114 | end 115 | -------------------------------------------------------------------------------- /lib/upwork/api/routers/messages.rb: -------------------------------------------------------------------------------- 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 2016(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 | class Messages 18 | ENTRY_POINT = 'api' 19 | 20 | # Init 21 | # 22 | # Arguments: 23 | # client: (Client) 24 | def initialize(client) 25 | @client = client 26 | @client.epoint = ENTRY_POINT 27 | end 28 | 29 | # Retrieve rooms information 30 | # 31 | # Arguments: 32 | # company: (String) 33 | # params: (Hash) 34 | def get_rooms(company, params = {}) 35 | $LOG.i "running " + __method__.to_s 36 | @client.get '/messages/v3/' + company + '/rooms', params 37 | end 38 | 39 | # Get a specific room information 40 | # 41 | # Arguments: 42 | # company: (String) 43 | # room_id: (String) 44 | # params: (Hash) 45 | def get_room_details(company, room_id, params = {}) 46 | $LOG.i "running " + __method__.to_s 47 | @client.get '/messages/v3/' + company + '/rooms/' + room_id, params 48 | end 49 | 50 | # Get messages from a specific room 51 | # 52 | # Arguments: 53 | # company: (String) 54 | # room_id: (String) 55 | # params: (Hash) 56 | def get_room_messages(company, room_id, params = {}) 57 | $LOG.i "running " + __method__.to_s 58 | @client.get '/messages/v3/' + company + '/rooms/' + room_id + '/stories', params 59 | end 60 | 61 | # Get a specific room by offer ID 62 | # 63 | # Arguments: 64 | # company: (String) 65 | # offer_id: (String) 66 | # params: (Hash) 67 | def get_room_by_offer(company, offer_id, params = {}) 68 | $LOG.i "running " + __method__.to_s 69 | @client.get '/messages/v3/' + company + '/rooms/offers/' + offer_id, params 70 | end 71 | 72 | # Get a specific room by application ID 73 | # 74 | # Arguments: 75 | # company: (String) 76 | # application_id: (String) 77 | # params: (Hash) 78 | def get_room_by_application(company, application_id, params = {}) 79 | $LOG.i "running " + __method__.to_s 80 | @client.get '/messages/v3/' + company + '/rooms/applications/' + application_id, params 81 | end 82 | 83 | # Get a specific room by contract ID 84 | # 85 | # Arguments: 86 | # company: (String) 87 | # contract_id: (String) 88 | # params: (Hash) 89 | def get_room_by_contract(company, contract_id, params = {}) 90 | $LOG.i "running " + __method__.to_s 91 | @client.get '/messages/v3/' + company + '/rooms/contracts/' + contract_id, params 92 | end 93 | 94 | # Create a new room 95 | # 96 | # Arguments: 97 | # company: (String) 98 | # params: (Hash) 99 | def create_room(company, params = {}) 100 | $LOG.i "running " + __method__.to_s 101 | @client.post '/messages/v3/' + company + '/rooms', params 102 | end 103 | 104 | # Send a message to a room 105 | # 106 | # Arguments: 107 | # company: (String) 108 | # room_id: (String) 109 | # params: (Hash) 110 | def send_message_to_room(company, room_id, params = {}) 111 | $LOG.i "running " + __method__.to_s 112 | @client.post '/messages/v3/' + company + '/rooms/' + room_id + '/stories', params 113 | end 114 | 115 | # Send a message to a batch of rooms 116 | # 117 | # Arguments: 118 | # company: (String) 119 | # params: (Hash) 120 | def send_message_to_rooms(company, params = {}) 121 | $LOG.i "running " + __method__.to_s 122 | @client.post '/messages/v3/' + company + '/stories/batch', params 123 | end 124 | 125 | # Update a room settings 126 | # 127 | # Arguments: 128 | # company: (String) 129 | # room_id: (String) 130 | # username: (String) 131 | # params: (Hash) 132 | def update_room_settings(company, room_id, username, params = {}) 133 | $LOG.i "running " + __method__.to_s 134 | @client.put '/messages/v3/' + company + '/rooms/' + room_id + '/users/' + username, params 135 | end 136 | 137 | # Update the metadata of a room 138 | # 139 | # Arguments: 140 | # company: (String) 141 | # room_id: (String) 142 | # params: (Hash) 143 | def update_room_metadata(company, room_id, params = {}) 144 | $LOG.i "running " + __method__.to_s 145 | @client.put '/messages/v3/' + company + '/rooms/' + room_id, params 146 | end 147 | end 148 | end 149 | end 150 | end 151 | -------------------------------------------------------------------------------- /lib/upwork/api/client.rb: -------------------------------------------------------------------------------- 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 | require 'json' 15 | require 'uri' 16 | 17 | 18 | module Upwork 19 | module Api 20 | # Client for accessing API 21 | class Client 22 | DATA_FORMAT = 'json' 23 | OVERLOAD_VAR = "http_method" 24 | 25 | URI_AUTH = "/services/api/auth" 26 | URI_RTOKEN = "/auth/v1/oauth/token/request" 27 | URI_ATOKEN = "/auth/v1/oauth/token/access" 28 | 29 | attr_accessor :epoint 30 | attr_reader :url_auth, :url_rtoken, :url_atoken 31 | 32 | # Init client 33 | # 34 | # Arguments: 35 | # config: (Config) 36 | def initialize(config) 37 | $LOG.i('initializing client') 38 | @config = config 39 | @epoint = Upwork::Api::DEFAULT_EPOINT 40 | @url_auth, @url_rtoken, @url_atoken = Upwork::Api::BASE_HOST + URI_AUTH, self.full_url(URI_RTOKEN), self.full_url(URI_ATOKEN) 41 | end 42 | 43 | # Start auth process and get authorization token 44 | def get_authorization_url(oauth_callback = "oob") 45 | $LOG.i "requesting autorization token" 46 | @consumer=OAuth::Consumer.new @config.consumer_key, 47 | @config.consumer_secret, 48 | {:site => Upwork::Api::BASE_HOST, 49 | :request_token_path => '/' + Upwork::Api::DEFAULT_EPOINT + URI_RTOKEN, 50 | :access_token_path => '/' + Upwork::Api::DEFAULT_EPOINT + URI_ATOKEN, 51 | :authorize_path => URI_AUTH, 52 | :signature_method => @config.signature_method} 53 | 54 | @request_token = @consumer.get_request_token({:oauth_callback => oauth_callback}) 55 | $LOG.i "got request token pair", @request_token 56 | 57 | $LOG.i "building authorization url, which is", @request_token.authorize_url 58 | @request_token.authorize_url 59 | end 60 | 61 | # Finish auth process and get access token 62 | # 63 | # Arguments: 64 | # verifier: (String) 65 | def get_access_token(verifier) 66 | $LOG.i "getting access token pair" 67 | @access_token = @request_token.get_access_token(:oauth_verifier => verifier) 68 | $LOG.i "got access token pair", @access_token 69 | $LOG.i "save access token data in config object" 70 | 71 | @config.access_token = @access_token.token 72 | @config.access_secret = @access_token.secret 73 | 74 | @access_token 75 | end 76 | 77 | # Run GET request 78 | # 79 | # Arguments: 80 | # uri: (String) 81 | # param: (Hash) 82 | def get(uri, params = {}) 83 | send_request(uri, :get, params) 84 | end 85 | 86 | # Run POST request 87 | # 88 | # Arguments: 89 | # uri: (String) 90 | # param: (Hash) 91 | def post(uri, params = {}) 92 | send_request(uri, :post, params) 93 | end 94 | 95 | # Run PUT request 96 | # 97 | # Arguments: 98 | # uri: (String) 99 | # param: (Hash) 100 | def put(uri, params = {}) 101 | send_request(uri, :put, params) 102 | end 103 | 104 | # Run DELETE request 105 | # 106 | # Arguments: 107 | # uri: (String) 108 | # param: (Hash) 109 | def delete(uri, params = {}) 110 | send_request(uri, :delete, params) 111 | end 112 | 113 | # Get full URL 114 | def full_url(uri) # :nodoc: 115 | Upwork::Api::BASE_HOST + '/' + (@epoint) + get_uri_with_format(uri); 116 | end 117 | 118 | # Get URI with :format 119 | def get_uri_with_format(uri) # :nodoc: 120 | uri + ((@epoint == 'api') ? '.' + DATA_FORMAT : '') 121 | end 122 | 123 | private 124 | 125 | # get url with parameters for get requests 126 | def get_url_with_params(path, params) 127 | "#{path}?perf=1".concat(params.collect{|k,v| "#{k}=#{OAuth::Helper::escape(v.to_s)}"}.join("&")) 128 | end 129 | 130 | # Send request 131 | def send_request(uri, method = :get, params = {}) # :nodoc: 132 | $LOG.i "send request for url", uri 133 | $LOG.i "and method", method 134 | 135 | if method == :put or method == :delete 136 | $LOG.i "add overload parameter" 137 | params[OVERLOAD_VAR] = method.to_s 138 | end 139 | 140 | $LOG.i "and parameters", params 141 | 142 | @consumer=OAuth::Consumer.new @config.consumer_key, 143 | @config.consumer_secret, 144 | {:site => Upwork::Api::BASE_HOST + '/' + @epoint, 145 | :http_method => method} 146 | @access_token = OAuth::AccessToken.new(@consumer, @config.access_token, @config.access_secret) 147 | 148 | case method 149 | when :get 150 | url = get_url_with_params get_uri_with_format(uri), params 151 | response = @access_token.get(url).body 152 | when :post, :put, :delete 153 | response = @access_token.post(get_uri_with_format(uri), params).body 154 | else 155 | raise ArgumentError, "Don't know how to handle http method: :#{method.to_s}" 156 | end 157 | $LOG.i "got response from server", response 158 | JSON.parse(response) 159 | end 160 | 161 | end 162 | end 163 | end 164 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | --------------------------------------------------------------------------------