height-api 0.0.1

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: b45bd952c9fcf17f329987f231db25cec405e9b6f2e1917ab974f90cc458a5a1
4
+ data.tar.gz: 36f22f469e81fffffc74ab8155452efb6b44e592c30f2c813cb324a530c1c7b7
5
+ SHA512:
6
+ metadata.gz: d69e0344946cf9814d2fcce3cea22c383ef08d1108c932e97e61b91defac66278e5a59b984fd74a044d336d02497faa5fb5e15389d4dcc66a594abcc2f26c1a0
7
+ data.tar.gz: 7f4faad3d023507bc7393fd3628aad60e661a55cb507a9a75700f681de66530c0e05a0d7e3a7d8b0b3848b9a02da7b9b8647094829256abce989f22a31ff7d61
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .envrc
13
+ .byebug_history
14
+
15
+ tags
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 0.0.1 Initial release
4
+
5
+ - List lists
6
+ - List tasks in a list
7
+ - Find task
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in height-api.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ height-api (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ byebug (11.1.3)
12
+ crack (0.4.5)
13
+ rexml
14
+ diff-lcs (1.4.4)
15
+ hashdiff (1.0.1)
16
+ public_suffix (4.0.6)
17
+ rake (12.3.3)
18
+ rexml (3.2.4)
19
+ rspec (3.10.0)
20
+ rspec-core (~> 3.10.0)
21
+ rspec-expectations (~> 3.10.0)
22
+ rspec-mocks (~> 3.10.0)
23
+ rspec-core (3.10.1)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-expectations (3.10.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-mocks (3.10.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-support (3.10.2)
32
+ vcr (6.0.0)
33
+ webmock (3.12.2)
34
+ addressable (>= 2.3.6)
35
+ crack (>= 0.3.2)
36
+ hashdiff (>= 0.4.0, < 2.0.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ byebug
43
+ height-api!
44
+ rake (~> 12.0)
45
+ rspec (~> 3.0)
46
+ vcr
47
+ webmock
48
+
49
+ BUNDLED WITH
50
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Mauro Morales
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,72 @@
1
+ # Height API Ruby Gem
2
+
3
+ _**Warning**: This is still a work in progress. Expect changes in the API_
4
+
5
+ This gem is a Ruby implementation for [Height.app](https://height.app/)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'height-api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install height-api
22
+
23
+ ## Configuration
24
+
25
+ Set the environment variable `HEIGHT_API_KEY`
26
+
27
+ ## Usage
28
+
29
+ Create an instance of the client
30
+
31
+ ```ruby
32
+ height = Height.new
33
+ ```
34
+
35
+ From the client you can list lists
36
+
37
+ ```ruby
38
+ height.lists.list
39
+ ```
40
+
41
+ The result will be of type `Height::ListResponse` which you can access like any
42
+ other enumerable. Each item will be of a `Height::Model` type and have its own
43
+ methods. For example, we can get all tasks in a list
44
+
45
+ ```ruby
46
+ lists = height.lists.list
47
+ tasks = lists.first.task
48
+ ```
49
+
50
+ You can also get a task if you know the index or id
51
+
52
+ ```ruby
53
+ task = height.tasks.get(2)
54
+ ```
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
59
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
60
+ prompt that will allow you to experiment.
61
+
62
+ To install this gem onto your local machine, run `bundle exec rake install`.
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at
67
+ https://github.com/mauromorales/height-api.
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT
72
+ License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "height/api"
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__)
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,29 @@
1
+ require_relative 'lib/height/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "height-api"
5
+ spec.version = Height::VERSION
6
+ spec.authors = ["Mauro Morales"]
7
+ spec.email = ["contact@mauromorales.com"]
8
+
9
+ spec.summary = %q{Ruby implementation for Height's API}
10
+ spec.description = %q{Ruby implementation for Height's API}
11
+ spec.homepage = "https://github.com/mauromorales/height-api"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["changelog_uri"] = "https://github.com/mauromorales/height-api/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+ spec.add_development_dependency 'byebug', '~> 11.1.3'
27
+ spec.add_development_dependency 'vcr', '~> 6.0.0'
28
+ spec.add_development_dependency 'webmock', '~> 3.12.2'
29
+ end
data/lib/height-api.rb ADDED
@@ -0,0 +1 @@
1
+ require 'height'
data/lib/height.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'net/http'
3
+
4
+ require 'height/api'
5
+ require 'height/client'
6
+ require 'height/response'
7
+ require 'height/list_response'
8
+ require 'height/model'
9
+ require 'height/request'
10
+
11
+ module Height
12
+ class << self
13
+ def new
14
+ Height::Client.new
15
+ end
16
+ end
17
+ end
data/lib/height/api.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Height::API
2
+ require 'height/api/lists'
3
+ require 'height/api/tasks'
4
+ end
@@ -0,0 +1,9 @@
1
+ class Height::API::Lists
2
+ class << self
3
+ def list
4
+ res = Height::Request.get('lists')
5
+
6
+ Height::ListResponse.parse(res.body)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ class Height::API::Tasks
2
+ class << self
3
+ def search(filter)
4
+ query = { 'filters' => filter.to_json }
5
+ res = Height::Request.get('tasks', query)
6
+
7
+ Height::ListResponse.parse(res.body)
8
+ end
9
+
10
+ def get(id_or_index)
11
+ res = Height::Request.get("tasks/#{id_or_index}")
12
+
13
+ Height::Response.parse(res.body)
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,9 @@
1
+ class Height::Client
2
+ def lists
3
+ Height::API::Lists
4
+ end
5
+
6
+ def tasks
7
+ Height::API::Tasks
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ class Height::ListResponse
2
+ include ::Enumerable
3
+
4
+ class << self
5
+ def parse(json)
6
+ response = JSON.parse(json)
7
+ items = response['list'].map { |item| Height::Model.for(item) }
8
+
9
+ new(items)
10
+ end
11
+ end
12
+
13
+ def initialize(items)
14
+ @items = items
15
+ end
16
+
17
+ def empty?
18
+ count.zero?
19
+ end
20
+
21
+ def count
22
+ @items.count
23
+ end
24
+
25
+ def each(&block)
26
+ @items.each(&block)
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ require 'height/model/base'
2
+ require 'height/model/list'
3
+ require 'height/model/task'
4
+
5
+ module Height::Model
6
+ def self.for(attrs)
7
+ model = attrs['model'].capitalize
8
+
9
+ Object.const_get("Height::Model::#{model}").new(attrs)
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Height::Model
2
+ class Base
3
+ def initialize(attrs)
4
+ self.attributes.each do |key|
5
+ self.instance_variable_set("@#{key}", attrs[key.to_s])
6
+ define_singleton_method(key) do
7
+ self.instance_variable_get("@#{key}")
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module Height::Model
2
+ class List < Base
3
+ def attributes
4
+ [:id, :type, :key, :description, :url, :appearence]
5
+ end
6
+
7
+ def tasks
8
+ filters = {
9
+ "listIds" => {
10
+ "values" => [id]
11
+ }
12
+ }
13
+
14
+ Height::API::Tasks.search(filters)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Height::Model
2
+ class Task < Base
3
+ def attributes
4
+ [
5
+ :id, :index, :list_ids, :name, :description, :status,
6
+ :assignees_ids, :parent_task_id, :fields, :deleted, :deleted_at,
7
+ :deleted_by_user_id, :completed, :completed_at, :created_at,
8
+ :created_user_id, :last_activity_at, :url
9
+ ]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ class Height::Request
2
+ def self.get(endpoint, query = nil)
3
+ uri = URI("https://api.height.app/#{endpoint}")
4
+ http = Net::HTTP.new(uri.hostname, uri.port)
5
+ http.use_ssl = true
6
+ headers = {
7
+ 'Authorization' => "api-key #{ENV['HEIGHT_API_KEY']}",
8
+ 'Content-Type' => 'application/json'
9
+ }
10
+ uri.query = URI.encode_www_form(query) if query
11
+ req = Net::HTTP::Get.new(uri, headers)
12
+
13
+ http.request(req)
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ class Height::Response
2
+ class << self
3
+ def parse(json)
4
+ response = JSON.parse(json)
5
+ Height::Model.for(response)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Height
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: height-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mauro Morales
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: byebug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 11.1.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 11.1.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: vcr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 6.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 6.0.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.12.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.12.2
55
+ description: Ruby implementation for Height's API
56
+ email:
57
+ - contact@mauromorales.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - height-api.gemspec
73
+ - lib/height-api.rb
74
+ - lib/height.rb
75
+ - lib/height/api.rb
76
+ - lib/height/api/lists.rb
77
+ - lib/height/api/tasks.rb
78
+ - lib/height/client.rb
79
+ - lib/height/list_response.rb
80
+ - lib/height/model.rb
81
+ - lib/height/model/base.rb
82
+ - lib/height/model/list.rb
83
+ - lib/height/model/task.rb
84
+ - lib/height/request.rb
85
+ - lib/height/response.rb
86
+ - lib/height/version.rb
87
+ homepage: https://github.com/mauromorales/height-api
88
+ licenses:
89
+ - MIT
90
+ metadata:
91
+ homepage_uri: https://github.com/mauromorales/height-api
92
+ source_code_uri: https://github.com/mauromorales/height-api
93
+ changelog_uri: https://github.com/mauromorales/height-api/CHANGELOG.md
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.3.0
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.0.3
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Ruby implementation for Height's API
113
+ test_files: []