marlens-harvest-api-v2 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aba7eadb7f89f25f1e45ad2371a3cc691360ad4c885ab8ea20abb6aa57145be4
4
+ data.tar.gz: 387642a33d117cb67503ed9119f4da4ea5c5096fa31f8d17de7e2d6e53a9eed6
5
+ SHA512:
6
+ metadata.gz: 534a76a5e7f6b2434061b604d68930274eaa8d9bf5f70703839089d00ce0d79561746e0081b0b61704eb3637f8df6a82a984faa26a2dc96e48712dfa3ba3617c
7
+ data.tar.gz: ecd9f2a214abef00170081b60dc61c4286f4e6473b66bb7d41bf8efaa49c7e0d1f419bb8be1f0f187a9c32a931e58a1723b1689a16a9824f0c089d02223ac479
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Marlen Brunner
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.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Marlens Harvest API V2
2
+
3
+ Small Ruby client for the Harvest API V2. It uses Ruby's standard library and exposes `Marlens::HarvestApiV2::Client#request` plus the task-assignment and duration-time-entry calls used by the companion `harvest-time-off` CLI.
4
+
5
+ ```ruby
6
+ require "marlens/harvest_api_v2"
7
+ client = Marlens::HarvestApiV2::Client.from_environment
8
+ client.create_time_entry(
9
+ project_id: 48_730_683,
10
+ task_id: 8_083_365,
11
+ spent_date: Date.new(2026, 7, 15),
12
+ hours: 7.5,
13
+ notes: "Vacation"
14
+ )
15
+ ```
16
+
17
+ Set `HARVEST_ACCESS_TOKEN` and `HARVEST_ACCOUNT_ID`; the client does not read credential files.
18
+
19
+ ## Feature and release workflow
20
+
21
+ Follow [`docs/workflows/feature-workflow.md`](docs/workflows/feature-workflow.md): issue and acceptance criteria, issue branch, tested draft PR, reviewed merge to `main`, version bump, RubyGems publish, remote verification, and isolated install smoke test.
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ module Marlens::HarvestApiV2
8
+ class Client
9
+ API_URL = "https://api.harvestapp.com".freeze
10
+ USER_AGENT = "marlens-harvest-api-v2/#{VERSION}".freeze
11
+
12
+ def self.from_environment(environment: ENV)
13
+ access_token = environment.fetch("HARVEST_ACCESS_TOKEN", "")
14
+ account_id = environment.fetch("HARVEST_ACCOUNT_ID", "")
15
+ raise Error, "HARVEST_ACCESS_TOKEN is required" if access_token.empty?
16
+ raise Error, "HARVEST_ACCOUNT_ID is required" if account_id.empty?
17
+
18
+ new(access_token:, account_id:)
19
+ end
20
+
21
+ def initialize(access_token:, account_id:, base_url: API_URL, executor: nil)
22
+ @access_token = access_token
23
+ @account_id = account_id
24
+ @base_url = base_url
25
+ @executor = executor || method(:perform_request)
26
+ end
27
+
28
+ def request(method, path, params: {}, body: nil)
29
+ uri = URI.join(@base_url, path)
30
+ uri.query = URI.encode_www_form(params) unless params.empty?
31
+ request = request_class(method).new(uri)
32
+ request["Content-Type"] = "application/json" if body
33
+ request.body = JSON.generate(body) if body
34
+ request["Authorization"] = "Bearer #{@access_token}"
35
+ request["Harvest-Account-Id"] = @account_id
36
+ request["User-Agent"] = USER_AGENT
37
+
38
+ response = @executor.call(request)
39
+ return JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)
40
+
41
+ raise Error.new(response.code, error_message(response.body))
42
+ rescue JSON::ParserError
43
+ raise Error, "Harvest API returned invalid JSON"
44
+ end
45
+
46
+ def active_task_assignments
47
+ request(:get, "/v2/task_assignments", params: { is_active: true, per_page: 2000 }).fetch("task_assignments")
48
+ end
49
+
50
+ def create_time_entry(project_id:, task_id:, spent_date:, hours:, notes: nil)
51
+ body = { project_id:, task_id:, spent_date: spent_date.iso8601, hours: }
52
+ body[:notes] = notes unless notes.nil? || notes.empty?
53
+ request(:post, "/v2/time_entries", body:)
54
+ end
55
+
56
+ private
57
+
58
+ def request_class(method)
59
+ {
60
+ get: Net::HTTP::Get,
61
+ post: Net::HTTP::Post,
62
+ patch: Net::HTTP::Patch,
63
+ delete: Net::HTTP::Delete
64
+ }.fetch(method.to_sym)
65
+ rescue KeyError
66
+ raise Error, "unsupported HTTP method: #{method}"
67
+ end
68
+
69
+ def error_message(body)
70
+ JSON.parse(body).fetch("message", body)
71
+ rescue JSON::ParserError
72
+ body
73
+ end
74
+
75
+ def perform_request(request)
76
+ Net::HTTP.start(
77
+ request.uri.host,
78
+ request.uri.port,
79
+ use_ssl: request.uri.scheme == "https"
80
+ ) { |http| http.request(request) }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Marlens
4
+ module HarvestApiV2
5
+ class Error < StandardError
6
+ attr_reader :status
7
+
8
+ def initialize(status = nil, message = nil)
9
+ @status = message ? status : nil
10
+ super(message || status)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Marlens
4
+ module HarvestApiV2
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "marlens/harvest_api_v2/version"
4
+ require "marlens/harvest_api_v2/error"
5
+ require "marlens/harvest_api_v2/client"
6
+
7
+ module Marlens
8
+ module HarvestApiV2
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marlens-harvest-api-v2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marlen Brunner
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - klondikemarlen@gmail.com
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - LICENSE.txt
19
+ - README.md
20
+ - lib/marlens/harvest_api_v2.rb
21
+ - lib/marlens/harvest_api_v2/client.rb
22
+ - lib/marlens/harvest_api_v2/error.rb
23
+ - lib/marlens/harvest_api_v2/version.rb
24
+ homepage: https://github.com/klondikemarlen/harvest-api-v2
25
+ licenses:
26
+ - MIT
27
+ metadata:
28
+ source_code_uri: https://github.com/klondikemarlen/harvest-api-v2
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '3.2'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 4.0.3
44
+ specification_version: 4
45
+ summary: Small Ruby client for Harvest API V2.
46
+ test_files: []