Class: DigitalHumani::SDK
- Inherits:
-
Object
- Object
- DigitalHumani::SDK
- Defined in:
- lib/digitalhumani.rb
Instance Attribute Summary collapse
-
#enterprise_id ⇒ Object
Allow enterprise_id to be read, written.
Instance Method Summary collapse
-
#enterprise(enterprise_id: @enterprise_id) ⇒ Object
Get enterprise by ID.
-
#initialize(&block) ⇒ SDK
constructor
Initilaize instance w/ API key, environment, and optionally enterpriseId.
-
#plant_tree(enterprise_id: @enterprise_id, project_id:, user:, treeCount: 1) ⇒ Object
Plant tree.
-
#project(project_id:) ⇒ Object
Get project by ID.
-
#projects ⇒ Object
Get list of all projects.
-
#tree(uuid:) ⇒ Object
Get tree by UUID.
-
#tree_count(enterprise_id: @enterprise_id, start_date: "", end_date: "", month: "", user: "") ⇒ Object
Get tree count for enterprise - for date range, month, or user.
Constructor Details
#initialize(&block) ⇒ SDK
Initilaize instance w/ API key, environment, and optionally enterpriseId
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/digitalhumani.rb', line 15 def initialize(&block) instance_eval(&block) # Validate api_key, environment inputs if !@api_key or @api_key === "" raise "Error: @api_key parameter required" end if !@environment or !["production","sandbox","local"].include?(@environment) raise "Error: @environment parameter required and must be one of 'production','sandbox'" end # Set API base url based on environment case @environment when "production" @url = "https://api.digitalhumani.com/" when "sandbox" @url = "https://api.sandbox.digitalhumani.com" when "local" @url = "http://localhost:3000" end end |
Instance Attribute Details
#enterprise_id ⇒ Object
Allow enterprise_id to be read, written
12 13 14 |
# File 'lib/digitalhumani.rb', line 12 def enterprise_id @enterprise_id end |
Instance Method Details
#enterprise(enterprise_id: @enterprise_id) ⇒ Object
Get enterprise by ID
38 39 40 41 42 43 44 |
# File 'lib/digitalhumani.rb', line 38 def enterprise(enterprise_id: @enterprise_id) if !enterprise_id raise "Error: `enterprise_id` not set" end request(http_method: :get, endpoint: "/enterprise/#{enterprise_id}") end |
#plant_tree(enterprise_id: @enterprise_id, project_id:, user:, treeCount: 1) ⇒ Object
Plant tree
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/digitalhumani.rb', line 61 def plant_tree(enterprise_id: @enterprise_id, project_id:, user:, treeCount: 1) if !enterprise_id raise "Error: `enterprise_id` not set" end if !project_id raise "Error: `project_id` parameter required" end request(endpoint: "/tree", http_method: :post, params: { enterpriseId: enterprise_id, projectId: project_id, user: user, treeCount: treeCount }) end |
#project(project_id:) ⇒ Object
Get project by ID
52 53 54 55 56 57 58 |
# File 'lib/digitalhumani.rb', line 52 def project(project_id:) if !project_id raise "Error: `project_id` parameter required" end request(endpoint: "/project/#{project_id}", http_method: :get) end |
#projects ⇒ Object
Get list of all projects
47 48 49 |
# File 'lib/digitalhumani.rb', line 47 def projects() request(endpoint: "/project", http_method: :get) end |
#tree(uuid:) ⇒ Object
Get tree by UUID
78 79 80 81 82 83 |
# File 'lib/digitalhumani.rb', line 78 def tree(uuid:) if !uuid raise "Error: `uuid` parameter required" end request(endpoint: "/tree/#{uuid}", http_method: :get) end |
#tree_count(enterprise_id: @enterprise_id, start_date: "", end_date: "", month: "", user: "") ⇒ Object
Get tree count for enterprise - for date range, month, or user
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/digitalhumani.rb', line 86 def tree_count(enterprise_id: @enterprise_id, start_date: "", end_date: "", month: "", user: "") if !enterprise_id raise "Error: `enterprise_id` not set" end if start_date and start_date != "" if end_date and end_date != "" # Request tree count over date range request(http_method: :get, endpoint: "/enterprise/#{enterprise_id}/treeCount", params: { startDate: start_date, endDate: end_date }) else raise "Error: Both `start_date` and `end_date` parameters required" end elsif month and month != "" # Request tree count for month request(http_method: :get, endpoint: "/enterprise/#{enterprise_id}/treeCount/#{month}") elsif user and user != "" # Request tree count for user request(http_method: :get, endpoint: "/tree", params: { enterpriseId: enterprise_id, user: user }) else raise "Error: invalid parameters. Must specify `start_date`/`end_date`, `month`, or `user`" end end |