harvest-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8f62238a0554a995b3f835926dadec05a7153991a147a555698f137212f07ffa
4
+ data.tar.gz: ac387031f0d107b762a673d6e3f94c4f48e0fa52e6ff244deb6dd127c6e196a2
5
+ SHA512:
6
+ metadata.gz: e648a14b3fa5752b94ab3e760bad5297fc59a1663de73adbc78234c01b1d428d86dff8c22331fffea632375201cda2052915215e713e95a2d0c5fc8970628658
7
+ data.tar.gz: 56a9bdc24a5393c79f6be30f41c4eae411e2bbdb1c13d5dfd404fa39d967d30fd3d3d03169d0a7b8c249bff558b91e1ef6464d6c12b193726a55cfb2d4c91178
@@ -0,0 +1,51 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ /Gemfile.lock
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ .env
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+ *.bridgesupport
22
+ build-iPhoneOS/
23
+ build-iPhoneSimulator/
24
+
25
+ ## Specific to RubyMotion (use of CocoaPods):
26
+ #
27
+ # We recommend against adding the Pods directory to your .gitignore. However
28
+ # you should judge for yourself, the pros and cons are mentioned at:
29
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
+ #
31
+ # vendor/Pods/
32
+
33
+ ## Documentation cache and generated files:
34
+ /.yardoc/
35
+ /_yardoc/
36
+ /doc/
37
+ /rdoc/
38
+
39
+ ## Environment normalization:
40
+ /.bundle/
41
+ /vendor/bundle
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ # Gemfile.lock
47
+ # .ruby-version
48
+ # .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
@@ -0,0 +1,12 @@
1
+ FROM ruby:2.4.2
2
+
3
+ # app dependencies
4
+ RUN apt-get update -qq && apt-get install -y build-essential
5
+
6
+ ENV APP_HOME /opt/harvest_api
7
+ RUN mkdir -p $APP_HOME
8
+ WORKDIR $APP_HOME
9
+
10
+ # ADD . $APP_HOME/
11
+
12
+ # RUN bundle
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in harvest-api.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Zachary Chai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # Harvest API
2
+ A ruby wrapper for Harvest v2 API http://www.getharvest.com/api
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'harvest-api'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install harvest-api
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ # Create client with authentication credentials
24
+ client = Harvest.client(access_token: 'd7f9bjnf9', account_id: '183950', user_agent: 'HarvestAPI (yourname@example.com)')
25
+
26
+ # Fetch the authenticated user
27
+ client.users.me
28
+ ```
29
+
30
+ ## Supported features
31
+
32
+ - Time Entries
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "harvest"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ version: '3'
2
+ services:
3
+ gem:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile
7
+ volumes:
8
+ - .:/opt/harvest_api
9
+ - gem_cache:/usr/local/bundle
10
+ command: bash
11
+
12
+ volumes:
13
+ gem_cache:
14
+ driver: local
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "harvest"
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "harvest/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "harvest-api"
8
+ spec.version = Harvest::VERSION
9
+ spec.authors = ["Zachary Chai"]
10
+ spec.email = ["zachary.chai@outlook.com"]
11
+
12
+ spec.summary = %q{A ruby wrapper for Harvest v2 API http://www.getharvest.com/api}
13
+ spec.description = %q{A ruby wrapper for Harvest v2 API http://www.getharvest.com/api}
14
+ spec.homepage = "https://github.com/zach-chai/harvest-api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.required_ruby_version = '>= 2.0'
25
+
26
+ spec.add_dependency "faraday", "~> 0.13"
27
+ spec.add_dependency "faraday_middleware", "~> 0.12"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+ spec.add_development_dependency "byebug"
33
+ end
@@ -0,0 +1,21 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ require 'byebug'
5
+
6
+ require 'harvest/version'
7
+ require 'harvest/client'
8
+ require 'harvest/request'
9
+ require 'harvest/response'
10
+
11
+ require 'harvest/resource/base'
12
+ require 'harvest/resource/time_entry'
13
+ require 'harvest/resource/user'
14
+
15
+ module Harvest
16
+ class << self
17
+ def client *args
18
+ Client.new *args
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ require 'harvest/client/users'
2
+ require 'harvest/client/time_entries'
3
+
4
+ module Harvest
5
+ class Client
6
+ include TimeEntries
7
+ include Users
8
+
9
+ BASE_URL = 'https://api.harvestapp.com/v2'.freeze
10
+
11
+ attr_reader :connection
12
+
13
+ def initialize access_token: nil, account_id: nil, user_agent: nil
14
+ @connection = Faraday.new(url: BASE_URL) do |conn|
15
+ conn.request :json
16
+ conn.request :oauth2, access_token, token_type: :bearer
17
+
18
+ conn.headers = {
19
+ 'Harvest-Account-Id' => account_id,
20
+ 'User-Agent' => user_agent
21
+ }
22
+
23
+ conn.response :json, :content_type => /\bjson$/
24
+
25
+ conn.adapter Faraday.default_adapter
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ # curl -H "Authorization: Bearer $ACCESS_TOKEN" \
33
+ # -H "Harvest-Account-Id: $ACCOUNT_ID" \
34
+ # -H "User-Agent: MyApp (yourname@example.com)" \
35
+ # https://api.harvestapp.com/v2/users/me
@@ -0,0 +1,13 @@
1
+ module Harvest
2
+ class Client
3
+ class BaseApi
4
+ def initialize conn
5
+ @connection = conn
6
+ end
7
+
8
+ def build_url path = nil
9
+ [collection_name, path].join('/')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Harvest
2
+ class Client
3
+ module Helpers
4
+ module All
5
+ def all params = {}
6
+ res = Request.new(@connection, build_url, params).get
7
+ if res.success?
8
+ res.body[collection_name].map { |te| resource.new(te) }
9
+ else
10
+ res.error
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Harvest
2
+ class Client
3
+ module Helpers
4
+ module Create
5
+ def create body
6
+ res = Request.new(@connection, build_url, body).post
7
+ if res.success?
8
+ resource.new(res.body)
9
+ else
10
+ res.error
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Harvest
2
+ class Client
3
+ module Helpers
4
+ module Delete
5
+ def delete id
6
+ res = Request.new(@connection, build_url(id)).delete
7
+ if res.success?
8
+ resource.new(res.body)
9
+ else
10
+ res.error
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Harvest
2
+ class Client
3
+ module Helpers
4
+ module Find
5
+ def find id
6
+ res = Request.new(@connection, build_url(id)).get
7
+ if res.success?
8
+ resource.new(res.body)
9
+ else
10
+ res.error
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Harvest
2
+ class Client
3
+ module Helpers
4
+ module Update
5
+ def update id, body
6
+ res = Request.new(@connection, build_url(id), body).patch
7
+ if res.success?
8
+ resource.new(res.body)
9
+ else
10
+ res.error
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ require 'harvest/client/base_api'
2
+ require 'harvest/client/helpers/all'
3
+ require 'harvest/client/helpers/find'
4
+ require 'harvest/client/helpers/create'
5
+ require 'harvest/client/helpers/update'
6
+ require 'harvest/client/helpers/delete'
7
+
8
+ module Harvest
9
+ class Client
10
+ module TimeEntries
11
+ def time_entries
12
+ TimeEntriesApi.new(connection)
13
+ end
14
+
15
+ class TimeEntriesApi < BaseApi
16
+ include Helpers::All
17
+ include Helpers::Find
18
+ include Helpers::Create
19
+ include Helpers::Update
20
+ include Helpers::Delete
21
+
22
+ def resource
23
+ Resource::TimeEntry
24
+ end
25
+
26
+ def collection_name
27
+ 'time_entries'
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ require 'harvest/client/base_api'
2
+ require 'harvest/client/helpers/all'
3
+ require 'harvest/client/helpers/find'
4
+ require 'harvest/client/helpers/create'
5
+
6
+ module Harvest
7
+ class Client
8
+ module Users
9
+ def users
10
+ UsersApi.new(connection)
11
+ end
12
+
13
+ class UsersApi < BaseApi
14
+ include Helpers::All
15
+ include Helpers::Find
16
+ include Helpers::Create
17
+
18
+ def me
19
+ res = Request.new(@connection, build_url('me')).get
20
+ if res.success?
21
+ resource.new(res.body)
22
+ else
23
+ res.error
24
+ end
25
+ end
26
+
27
+ def resource
28
+ Resource::User
29
+ end
30
+
31
+ def collection_name
32
+ 'users'
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ module Harvest
2
+ class Request
3
+ attr_accessor :resource, :params
4
+
5
+ def initialize conn, path, params = {}
6
+ @connection = conn
7
+ @path = path
8
+ @params = params
9
+ end
10
+
11
+ def get
12
+ res = @connection.get do |req|
13
+ req.url @path, @params
14
+ end
15
+ Response.new res
16
+ end
17
+
18
+ def post
19
+ res = @connection.post do |req|
20
+ req.url @path
21
+ req.body = @params
22
+ end
23
+ Response.new res
24
+ end
25
+
26
+ def patch
27
+ res = @connection.patch do |req|
28
+ req.url @path
29
+ req.body = @params
30
+ end
31
+ Response.new res
32
+ end
33
+
34
+ def delete
35
+ res = @connection.delete do |req|
36
+ req.url @path
37
+ end
38
+ Response.new res
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ module Harvest
2
+ module Resource
3
+ class Base
4
+ class << self
5
+ def attributes *attrs
6
+ if attrs.any?
7
+ @@attributes = attrs
8
+ attr_reader *attrs
9
+ self
10
+ else
11
+ @@attributes
12
+ end
13
+ end
14
+ end
15
+
16
+ def initialize attr_map
17
+ attr_map.each do |attribute, value|
18
+ instance_variable_set("@#{attribute}", value)
19
+ end
20
+ end
21
+
22
+ def attributes
23
+ self.class.attributes
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module Harvest
2
+ module Resource
3
+ class TimeEntry < Base
4
+ attributes :id,
5
+ :spent_date,
6
+ :user,
7
+ :user_assignment,
8
+ :client,
9
+ :project,
10
+ :task,
11
+ :task_assignment,
12
+ :external_reference,
13
+ :invoice,
14
+ :hours,
15
+ :notes,
16
+ :is_locked,
17
+ :locked_reason,
18
+ :is_closed,
19
+ :is_billed,
20
+ :timer_started_at,
21
+ :started_time,
22
+ :ended_time,
23
+ :is_running,
24
+ :billable,
25
+ :budgeted,
26
+ :billable_rate,
27
+ :cost_rate,
28
+ :created_at,
29
+ :updated_at
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ module Harvest
2
+ module Resource
3
+ class User < Base
4
+ attributes :id,
5
+ :first_name,
6
+ :last_name,
7
+ :email,
8
+ :telephone,
9
+ :timezone,
10
+ :has_access_to_all_future_projects,
11
+ :is_contractor,
12
+ :is_admin,
13
+ :is_project_manager,
14
+ :can_see_rates,
15
+ :can_create_projects,
16
+ :can_create_invoices,
17
+ :is_active,
18
+ :weekly_capacity,
19
+ :default_hourly_rate,
20
+ :cost_rate,
21
+ :roles,
22
+ :avatar_url,
23
+ :created_at,
24
+ :updated_at
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module Harvest
2
+ class Response
3
+ extend Forwardable
4
+
5
+ def initialize res
6
+ @res = res
7
+ end
8
+
9
+ def error
10
+ return if success?
11
+ body
12
+ end
13
+
14
+ def_delegators :@res, :success?, :status, :body
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Harvest
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harvest-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zachary Chai
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A ruby wrapper for Harvest v2 API http://www.getharvest.com/api
98
+ email:
99
+ - zachary.chai@outlook.com
100
+ executables:
101
+ - harvest-api
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Dockerfile
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - docker-compose.yml
114
+ - exe/harvest-api
115
+ - harvest-api.gemspec
116
+ - lib/harvest.rb
117
+ - lib/harvest/client.rb
118
+ - lib/harvest/client/base_api.rb
119
+ - lib/harvest/client/helpers/all.rb
120
+ - lib/harvest/client/helpers/create.rb
121
+ - lib/harvest/client/helpers/delete.rb
122
+ - lib/harvest/client/helpers/find.rb
123
+ - lib/harvest/client/helpers/update.rb
124
+ - lib/harvest/client/time_entries.rb
125
+ - lib/harvest/client/users.rb
126
+ - lib/harvest/request.rb
127
+ - lib/harvest/resource/base.rb
128
+ - lib/harvest/resource/time_entry.rb
129
+ - lib/harvest/resource/user.rb
130
+ - lib/harvest/response.rb
131
+ - lib/harvest/version.rb
132
+ homepage: https://github.com/zach-chai/harvest-api
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '2.0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.7.2
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: A ruby wrapper for Harvest v2 API http://www.getharvest.com/api
156
+ test_files: []