digitalhumani 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 14a663d43b2ef4aa923f1731936a8e8da8919412519b35b777f2c9dc102e6360
4
+ data.tar.gz: 13c0e230523558df5a48ce8023fcafb762914775f0fe98f0885b9903ea76f6af
5
+ SHA512:
6
+ metadata.gz: 9c2aa52feacbbf7232f08325ef9aa791ef864f6a765182d80eda340e28b15e4d776fdb22d234056f5021cbd5c4c482c38a1b760c12fc959fd5312a3b6aa05659
7
+ data.tar.gz: 73fcc12cd9faf8ad561b4f2487a9c66942a401369be1026b3c557590fb75bc9b6cfa0761960f7b83402ef8f2a862bf05c9f8542f8217b6acc2ef010e012ec6ff
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-08-25
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in digitalhumani.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem 'webmock', '~> 3.14'
13
+
14
+ gem "faraday", "~> 1.7.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ digitalhumani (0.1.0)
5
+ faraday (~> 1.7.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ crack (0.4.5)
13
+ rexml
14
+ diff-lcs (1.4.4)
15
+ faraday (1.7.0)
16
+ faraday-em_http (~> 1.0)
17
+ faraday-em_synchrony (~> 1.0)
18
+ faraday-excon (~> 1.1)
19
+ faraday-httpclient (~> 1.0.1)
20
+ faraday-net_http (~> 1.0)
21
+ faraday-net_http_persistent (~> 1.1)
22
+ faraday-patron (~> 1.0)
23
+ faraday-rack (~> 1.0)
24
+ multipart-post (>= 1.2, < 3)
25
+ ruby2_keywords (>= 0.0.4)
26
+ faraday-em_http (1.0.0)
27
+ faraday-em_synchrony (1.0.0)
28
+ faraday-excon (1.1.0)
29
+ faraday-httpclient (1.0.1)
30
+ faraday-net_http (1.0.1)
31
+ faraday-net_http_persistent (1.2.0)
32
+ faraday-patron (1.0.0)
33
+ faraday-rack (1.0.0)
34
+ hashdiff (1.0.1)
35
+ multipart-post (2.1.1)
36
+ public_suffix (4.0.6)
37
+ rake (13.0.6)
38
+ rexml (3.2.4)
39
+ rspec (3.10.0)
40
+ rspec-core (~> 3.10.0)
41
+ rspec-expectations (~> 3.10.0)
42
+ rspec-mocks (~> 3.10.0)
43
+ rspec-core (3.10.1)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-expectations (3.10.1)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-mocks (3.10.2)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-support (3.10.2)
52
+ ruby2_keywords (0.0.5)
53
+ webmock (3.14.0)
54
+ addressable (>= 2.8.0)
55
+ crack (>= 0.3.2)
56
+ hashdiff (>= 0.4.0, < 2.0.0)
57
+
58
+ PLATFORMS
59
+ x86_64-darwin-20
60
+
61
+ DEPENDENCIES
62
+ digitalhumani!
63
+ faraday (~> 1.7.0)
64
+ rake (~> 13.0)
65
+ rspec (~> 3.0)
66
+ webmock (~> 3.14)
67
+
68
+ BUNDLED WITH
69
+ 2.2.26
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Digital Humani
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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Carl Scheller
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # DigitalHumani Ruby SDK
2
+
3
+ | :warning: | This gem is currently under development and not yet published nor recommended for production use |
4
+ | --------- | :----------------------------------------------------------------------------------------------- |
5
+
6
+ This repository hosts the DigitalHumani Ruby Gem SDK. It can be used for interacting with the DigitalHumani RaaS (Reforestation-as-a-Service) API.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'digitalhumani'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install digitalhumani
23
+
24
+ ## Preparation
25
+
26
+ - Create an account on [DigitalHumani,com](https://my.digitalhumani.com/register) and grab your API key from the **Developer** menu item.
27
+ - Review the [DigitalHumani documentation](https://docs.digitalhumani.com) to familiarize yourself with the environments, requests, projects, etc
28
+
29
+ ## Usage
30
+
31
+ ### Configuration
32
+
33
+ ```ruby
34
+ # Initialize the DigitalHumani SDK instance
35
+ dh = DigitalHumani::SDK.new do
36
+ @api_key = $API_KEY # your API key
37
+ @environment = "production" # "production" or "sandbox"
38
+ @enterprise_id = $ENTERPRISE_ID # optional; your enterprise ID
39
+ end
40
+ ```
41
+
42
+ Alternatively, you can specify and update the `enterprise_id` separately:
43
+
44
+ ```ruby
45
+ digitalHumani.enterprise_id = $ENTERPRISE_ID
46
+ ```
47
+
48
+ Note that when `enterprise_id` has been specified on the instance, it will be used as a default value on all below methods and therefore does not need to be provided as a parameter.
49
+
50
+ ### Trees
51
+
52
+ ```ruby
53
+ # Plant one or many trees
54
+ digitalHumani.plant_tree(enterprise_id: $ENTERPRISE_ID, project_id: '81818181', user: 'test@example.com', treeCount: 5)
55
+
56
+ # Get details of a single tree-planting request
57
+ digitalHumani.tree(uuid: $TREE_UUID)
58
+ ```
59
+
60
+ ### Enterprises
61
+
62
+ ```ruby
63
+ # Get enterprise by ID
64
+ digitalHumani.enterprise(enterprise_id: $ENTERPRISE_ID)
65
+
66
+ # Get count of trees planted by date range
67
+ digitalHumani.treeCount(enterprise_id: $ENTERPRISE_ID, start: '2021-01-01', end: '2022-01-01')
68
+
69
+ # Get count of trees planted for month
70
+ digitalHumani.treeCount(enterprise_id: $ENTERPRISE_ID, month: '2021-01')
71
+
72
+ # Get count of trees planted by specific user. User string will match what's specified in `plant_tree` call
73
+ digitalHumani.treeCount(enterprise_id: $ENTERPRISE_ID, user: 'test@example.com')
74
+ ```
75
+
76
+ ### Projects
77
+
78
+ ```ruby
79
+ # Get list of all projects
80
+ digitalHumani.projects()
81
+
82
+ # Get project by ID
83
+ digitalHumani.project(project_id: '81818181')
84
+ ```
85
+
86
+ ## Development
87
+
88
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
89
+
90
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at https://github.com/digitalhumani/digitalhumani-ruby-sdk.
95
+
96
+ ## License
97
+
98
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "digitalhumani"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DigitalHumani
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "faraday"
5
+ require_relative "digitalhumani/version"
6
+
7
+ module DigitalHumani
8
+ class Error < StandardError; end
9
+
10
+ class SDK
11
+ # Allow enterprise_id to be read, written
12
+ attr_accessor :enterprise_id
13
+
14
+ # Initilaize instance w/ API key, environment, and optionally enterpriseId
15
+ def initialize(&block)
16
+ instance_eval(&block)
17
+
18
+ # Validate api_key, environment inputs
19
+ if !@api_key or @api_key === ""
20
+ raise "Error: @api_key parameter required"
21
+ end
22
+ if !@environment or !["production","sandbox"].include?(@environment)
23
+ raise "Error: @environment parameter required and must be one of 'production','sandbox'"
24
+ end
25
+
26
+ # Set API base url based on environment
27
+ case @environment
28
+ when "production"
29
+ @url = "https://api.digitalhumani.com/"
30
+ when "sandbox"
31
+ @url = "https://api.sandbox.digitalhumani.com"
32
+ end
33
+ end
34
+
35
+ # Get enterprise by ID
36
+ def enterprise(enterprise_id: @enterprise_id)
37
+ if !enterprise_id
38
+ raise "Error: `enterprise_id` not set"
39
+ end
40
+
41
+ request(http_method: :get, endpoint: "/enterprise/#{enterprise_id}")
42
+ end
43
+
44
+ # Get list of all projects
45
+ def projects()
46
+ request(endpoint: "/project", http_method: :get)
47
+ end
48
+
49
+ # Get project by ID
50
+ def project(project_id:)
51
+ if !project_id
52
+ raise "Error: `project_id` parameter required"
53
+ end
54
+
55
+ request(endpoint: "/project/#{project_id}", http_method: :get)
56
+ end
57
+
58
+ # Plant tree
59
+ def plant_tree(enterprise_id: @enterprise_id, project_id:, user:, treeCount: 1)
60
+ if !enterprise_id
61
+ raise "Error: `enterprise_id` not set"
62
+ end
63
+ if !project_id
64
+ raise "Error: `project_id` parameter required"
65
+ end
66
+
67
+ request(endpoint: "/tree", http_method: :post, params: {
68
+ enterpriseId: enterprise_id,
69
+ projectId: project_id,
70
+ user: user,
71
+ treeCount: treeCount
72
+ })
73
+ end
74
+
75
+ # Get tree by UUID
76
+ def tree(uuid:)
77
+ if !uuid
78
+ raise "Error: `uuid` parameter required"
79
+ end
80
+ request(endpoint: "/tree/#{uuid}", http_method: :get)
81
+ end
82
+
83
+ # Get tree count for enterprise - for date range, month, or user
84
+ def tree_count(enterprise_id: @enterprise_id, start_date: "", end_date: "", month: "", user: "")
85
+ if !enterprise_id
86
+ raise "Error: `enterprise_id` not set"
87
+ end
88
+
89
+ if start_date and start_date != ""
90
+ if end_date and end_date != ""
91
+ # Request tree count over date range
92
+ request(http_method: :get, endpoint: "/enterprise/#{enterprise_id}/treeCount", params: {
93
+ startDate: start_date,
94
+ endDate: end_date
95
+ })
96
+ else
97
+ raise "Error: Both `start_date` and `end_date` parameters required"
98
+ end
99
+ elsif month and month != ""
100
+ # Request tree count for month
101
+ request(http_method: :get, endpoint: "/enterprise/#{enterprise_id}/treeCount/#{month}")
102
+ elsif user and user != ""
103
+ # Request tree count for user
104
+ request(http_method: :get, endpoint: "/tree", params: {
105
+ enterpriseId: enterprise_id,
106
+ user: user
107
+ })
108
+ else
109
+ raise "Error: invalid parameters. Must specify `start_date`/`end_date`, `month`, or `user`"
110
+ end
111
+ end
112
+
113
+ private
114
+
115
+ # Initialize Faraday connection
116
+ def client
117
+ @_client ||= Faraday.new(@url) do |client|
118
+ client.request :url_encoded
119
+ client.headers["X-API-KEY"] = @api_key if @api_key
120
+ client.headers["Content-Type"] = "application/json"
121
+ client.headers["User-Agent"] = "Digital Humani Ruby SDK"
122
+ end
123
+ end
124
+
125
+ # Send request via Faraday connection object, return JSON-parse response body
126
+ def request(http_method:, endpoint:, params: {})
127
+ params = JSON.generate(params) if !params.empty? and http_method != :get
128
+ response = client.public_send(http_method, endpoint, params)
129
+ JSON.parse(response.body)
130
+ end
131
+
132
+ end
133
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digitalhumani
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Carl Scheller
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-24 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: 1.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.14'
55
+ description:
56
+ email:
57
+ - carl@digitalhumani.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/digitalhumani.rb
73
+ - lib/digitalhumani/version.rb
74
+ homepage: https://digitalhumani.com
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ allowed_push_host: https://rubygems.org
79
+ homepage_uri: https://digitalhumani.com
80
+ source_code_uri: https://github.com/digitalhumani/ruby-sdk
81
+ changelog_uri: https://github.com/digitalhumani/ruby-sdk/CHANGELOG.md
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 2.4.0
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.1.4
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: The official Ruby SDK for DigitalHumani's RaaS (Reforestation-as-a-Service)
101
+ test_files: []