favro_api 0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/favro_api.gemspec +29 -0
- data/lib/favro_api/auth.rb +10 -0
- data/lib/favro_api/data_types/assignment.rb +11 -0
- data/lib/favro_api/data_types/base.rb +64 -0
- data/lib/favro_api/data_types/card.rb +33 -0
- data/lib/favro_api/data_types/collection.rb +16 -0
- data/lib/favro_api/data_types/column.rb +14 -0
- data/lib/favro_api/data_types/comment.rb +15 -0
- data/lib/favro_api/data_types/custom_field.rb +12 -0
- data/lib/favro_api/data_types/organization.rb +12 -0
- data/lib/favro_api/data_types/shared_to_user.rb +12 -0
- data/lib/favro_api/data_types/tag.rb +13 -0
- data/lib/favro_api/data_types/task.rb +16 -0
- data/lib/favro_api/data_types/tasklist.rb +14 -0
- data/lib/favro_api/data_types/user.rb +13 -0
- data/lib/favro_api/data_types/widget.rb +18 -0
- data/lib/favro_api/data_types.rb +15 -0
- data/lib/favro_api/driver.rb +71 -0
- data/lib/favro_api/fields.rb +12 -0
- data/lib/favro_api/parser.rb +47 -0
- data/lib/favro_api/request.rb +77 -0
- data/lib/favro_api/response.rb +47 -0
- data/lib/favro_api/version.rb +3 -0
- data/lib/favro_api.rb +29 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 294a91240ba310e875e06c2fd451c8653f040aef
|
4
|
+
data.tar.gz: 8efbe1cae2ad6687ab73c521c1c422d130edb882
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8b55534799e80edfbd43d1b117b115149447a55db54d00da4e86e9dd07986f5431ec86b836a5dc4a329efb954f6f39da5f08b93adc0ee3f0a2888fbcf6f5e14
|
7
|
+
data.tar.gz: 6976272ea14e7a65951139fab1270dcf6904d6ee61b39028cb52e053943fbdeda6f51e222fc0716419e23d18c1c62aea4ba6cc60a87b4d857eb3744035b57d1c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Sergey Besedin
|
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,43 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/kressh/favro_api.svg?branch=master)](https://travis-ci.org/kressh/favro_api)
|
2
|
+
|
3
|
+
# FavroApi
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/favro_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
TODO: Delete this and the text above, and describe your gem
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'favro_api'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install favro_api
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
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.
|
32
|
+
|
33
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/favro_api.
|
38
|
+
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
43
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "favro_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
|
data/bin/setup
ADDED
data/favro_api.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'favro_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "favro_api"
|
8
|
+
spec.version = FavroApi::VERSION
|
9
|
+
spec.authors = ["Sergey Besedin"]
|
10
|
+
spec.email = ["kr3ssh@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Favro API}
|
13
|
+
spec.description = %q{Written in ruby}
|
14
|
+
spec.homepage = "https://github.com/kressh/favro_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.add_dependency "faraday", "~> 0.10"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
require_relative '../fields'
|
4
|
+
require_relative '../parser'
|
5
|
+
|
6
|
+
module FavroApi
|
7
|
+
module DataTypes
|
8
|
+
class Array < ::Array
|
9
|
+
def self.new(value = [])
|
10
|
+
value ? super(value) : value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Hash < ::Hash
|
15
|
+
def self.new(value)
|
16
|
+
value.to_h
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class String < ::String
|
21
|
+
def self.new(value = '')
|
22
|
+
value.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Boolean
|
27
|
+
def self.new(value)
|
28
|
+
'true' == value.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Date < ::Date
|
33
|
+
def self.new(value)
|
34
|
+
return nil if value.nil?
|
35
|
+
value.is_a?(::Date) ? value : Date.parse(value.to_s)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Time < ::Time
|
40
|
+
def self.new(value)
|
41
|
+
return nil if value.nil?
|
42
|
+
value.is_a?(::Time) ? value : Time.parse(value.to_s)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Integer < ::Integer
|
47
|
+
def self.new(value)
|
48
|
+
value.to_i
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Float < ::Float
|
53
|
+
def self.new(value)
|
54
|
+
value.to_f
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class ComplexType
|
59
|
+
extend Parser
|
60
|
+
extend Fields
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module FavroApi
|
4
|
+
module DataTypes
|
5
|
+
class Card < ComplexType
|
6
|
+
|
7
|
+
field :cardId, String
|
8
|
+
field :cardCommonId, String
|
9
|
+
|
10
|
+
field :organizationId, String
|
11
|
+
field :widgetCommonId, String
|
12
|
+
field :columnId, String
|
13
|
+
field :parentCardId, String
|
14
|
+
field :isLane, Boolean
|
15
|
+
|
16
|
+
field :name, String
|
17
|
+
field :archived, Boolean
|
18
|
+
field :position, Float
|
19
|
+
|
20
|
+
field :dueDate, Time
|
21
|
+
field :startDate, Time
|
22
|
+
|
23
|
+
field :tags, Array[String]
|
24
|
+
field :customFields, Array[CustomField]
|
25
|
+
field :assignments, Array[Assignment]
|
26
|
+
|
27
|
+
field :detailedDescription, String
|
28
|
+
|
29
|
+
field :tasksTotal, Integer
|
30
|
+
field :tasksDone, Integer
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module FavroApi
|
4
|
+
module DataTypes
|
5
|
+
class Collection < ComplexType
|
6
|
+
field :collectionId, String
|
7
|
+
field :organizationId, String
|
8
|
+
field :name, String
|
9
|
+
field :sharedToUsers, Array[SharedToUser]
|
10
|
+
field :publicSharing, String
|
11
|
+
field :background, String
|
12
|
+
field :archived, Boolean
|
13
|
+
field :shareWidgetsByDefault, Boolean
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module FavroApi
|
4
|
+
module DataTypes
|
5
|
+
class Column < ComplexType
|
6
|
+
|
7
|
+
field :columnId, String
|
8
|
+
field :organizationId, String
|
9
|
+
field :widgetCommonId, String
|
10
|
+
field :name, String
|
11
|
+
field :position, Integer
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module FavroApi
|
4
|
+
module DataTypes
|
5
|
+
class Comment < ComplexType
|
6
|
+
field :commentId, String
|
7
|
+
field :organizationId, String
|
8
|
+
field :cardCommonId, String
|
9
|
+
field :comment, String
|
10
|
+
field :userId, String
|
11
|
+
field :created, Time
|
12
|
+
field :lastUpdated, Time
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module FavroApi
|
4
|
+
module DataTypes
|
5
|
+
class Task < ComplexType
|
6
|
+
|
7
|
+
field :taskId, String
|
8
|
+
field :taskListId, String
|
9
|
+
field :cardCommonId, String
|
10
|
+
field :organizationId, String
|
11
|
+
field :name, String
|
12
|
+
field :completed, Boolean
|
13
|
+
field :position, Integer
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module FavroApi
|
4
|
+
module DataTypes
|
5
|
+
class Tasklist < ComplexType
|
6
|
+
|
7
|
+
field :taskListId, String
|
8
|
+
field :cardCommonId, String
|
9
|
+
field :organizationId, String
|
10
|
+
field :name, String
|
11
|
+
field :position, Integer
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module FavroApi
|
4
|
+
module DataTypes
|
5
|
+
class Widget < ComplexType
|
6
|
+
|
7
|
+
field :widgetCommonId, String
|
8
|
+
field :organizationId, String
|
9
|
+
field :collectionIds, Array[String]
|
10
|
+
field :name, String
|
11
|
+
field :type, String
|
12
|
+
field :breakdownCardCommonId, String
|
13
|
+
field :publicSharing, String
|
14
|
+
field :color, String
|
15
|
+
field :sharedToUsers, Array[SharedToUser]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FavroApi
|
2
|
+
module DataTypes
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require_relative './data_types/shared_to_user'
|
7
|
+
require_relative './data_types/collection'
|
8
|
+
require_relative './data_types/custom_field'
|
9
|
+
require_relative './data_types/assignment'
|
10
|
+
require_relative './data_types/card'
|
11
|
+
require_relative './data_types/column'
|
12
|
+
require_relative './data_types/tag'
|
13
|
+
require_relative './data_types/widget'
|
14
|
+
require_relative './data_types/organization'
|
15
|
+
require_relative './data_types/user'
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative './request'
|
2
|
+
require_relative './data_types'
|
3
|
+
|
4
|
+
module FavroApi
|
5
|
+
class Driver
|
6
|
+
def cards(params = {})
|
7
|
+
response = paginated_request(:cards, params).fetch
|
8
|
+
|
9
|
+
response.parse(type: FavroApi::DataTypes::Card)
|
10
|
+
end
|
11
|
+
|
12
|
+
def collections(params = {})
|
13
|
+
response = paginated_request(:collections, params).fetch
|
14
|
+
|
15
|
+
response.parse(type: FavroApi::DataTypes::Collection)
|
16
|
+
end
|
17
|
+
|
18
|
+
def comments(params = {})
|
19
|
+
response = paginated_request(:comments, params).fetch
|
20
|
+
|
21
|
+
response.parse(type: FavroApi::DataTypes::Comment)
|
22
|
+
end
|
23
|
+
|
24
|
+
def custom_fields(params = {})
|
25
|
+
response = paginated_request(:custom_fields, params).fetch
|
26
|
+
|
27
|
+
response.parse
|
28
|
+
end
|
29
|
+
|
30
|
+
def organizations(params = {})
|
31
|
+
response = paginated_request(:organizations, params).fetch
|
32
|
+
|
33
|
+
response.parse(type: FavroApi::DataTypes::Organization)
|
34
|
+
end
|
35
|
+
|
36
|
+
def tasks(params = {})
|
37
|
+
response = paginated_request(:tasks, params).fetch
|
38
|
+
|
39
|
+
response.parse(type: FavroApi::DataTypes::Task)
|
40
|
+
end
|
41
|
+
|
42
|
+
def tasklists(params = {})
|
43
|
+
response = paginated_request(:tasklists, params).fetch
|
44
|
+
|
45
|
+
response.parse(type: FavroApi::DataTypes::Tasklist)
|
46
|
+
end
|
47
|
+
|
48
|
+
def users(params = {})
|
49
|
+
response = paginated_request(:users, params).fetch
|
50
|
+
|
51
|
+
response.parse(type: FavroApi::DataTypes::User)
|
52
|
+
end
|
53
|
+
|
54
|
+
def widgets(params = {})
|
55
|
+
response = paginated_request(:widgets, params).fetch
|
56
|
+
|
57
|
+
response.parse(type: FavroApi::DataTypes::Widget)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def paginated_request(endpoint, params)
|
63
|
+
Request.new(
|
64
|
+
endpoint: endpoint,
|
65
|
+
page: params.delete(:page),
|
66
|
+
last_response: params.delete(:last_response),
|
67
|
+
params: params
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module FavroApi
|
2
|
+
module Parser
|
3
|
+
class ParserError < RuntimeError; end
|
4
|
+
|
5
|
+
def new(*args)
|
6
|
+
if args.any?
|
7
|
+
return parse(*args)
|
8
|
+
end
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(data)
|
13
|
+
case data
|
14
|
+
when Array
|
15
|
+
parse_array(data)
|
16
|
+
when Hash
|
17
|
+
parse_hash(data)
|
18
|
+
else
|
19
|
+
raise ParserError, "Can't parse #{data.class.name}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def parse_hash(hash)
|
26
|
+
instance = new
|
27
|
+
fields.each do |field|
|
28
|
+
value = hash[field[:name].to_s]
|
29
|
+
instance.send("#{field[:name]}=", parse_field(field, value))
|
30
|
+
end
|
31
|
+
instance
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_array(array)
|
35
|
+
array.map do |data|
|
36
|
+
parse(data)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse_field(field, value = nil)
|
41
|
+
if field[:type].is_a?(Array) && array_field = field[:type][0]
|
42
|
+
return value.to_a.map {|val| array_field.new(val) }
|
43
|
+
end
|
44
|
+
field[:type].new(value)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative './response'
|
2
|
+
|
3
|
+
module FavroApi
|
4
|
+
class Request
|
5
|
+
|
6
|
+
API_URL = 'https://favro.com/api/v1'.freeze
|
7
|
+
|
8
|
+
ENDPOINTS = {
|
9
|
+
cards: '/cards',
|
10
|
+
collections: '/collections',
|
11
|
+
comments: '/comments',
|
12
|
+
custom_fields: '/customFields',
|
13
|
+
organizations: '/organizations',
|
14
|
+
tasks: '/tasks',
|
15
|
+
tasklists: '/tasklists',
|
16
|
+
users: '/users',
|
17
|
+
widgets: '/widgets'
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
attr_accessor :connection, :url, :endpoint, :params, :method,
|
21
|
+
:last_response, :page
|
22
|
+
|
23
|
+
def initialize(options = {})
|
24
|
+
self.url = options[:url]
|
25
|
+
self.endpoint = options[:endpoint]
|
26
|
+
self.method = options[:method] || :get
|
27
|
+
self.params = options[:params] || {}
|
28
|
+
self.last_response = options[:last_response]
|
29
|
+
self.page = options[:page]
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch
|
33
|
+
self.connection = Faraday.new("#{uri.scheme}://#{uri.hostname}") do |faraday|
|
34
|
+
faraday.adapter :net_http
|
35
|
+
faraday.basic_auth(FavroApi.auth.email, FavroApi.auth.token)
|
36
|
+
faraday.headers['organizationId'] = params.delete(:organization_id)
|
37
|
+
faraday.params['page'] = page || (last_response ? last_response.page + 1 : 0)
|
38
|
+
faraday.params['requestId'] = last_response&.request_id
|
39
|
+
end
|
40
|
+
|
41
|
+
response = Response.new(response: connection.send(method, uri.request_uri, params))
|
42
|
+
|
43
|
+
if response.error?
|
44
|
+
raise ApiError, "Got API error. Code: #{response.status}, message: #{response.body}"
|
45
|
+
end
|
46
|
+
|
47
|
+
response
|
48
|
+
end
|
49
|
+
|
50
|
+
class << self
|
51
|
+
def fetch(endpoint, page: nil, last_response: nil, params: {})
|
52
|
+
new(
|
53
|
+
endpoint: endpoint,
|
54
|
+
last_response: last_response,
|
55
|
+
page: page,
|
56
|
+
method: :get,
|
57
|
+
params: params
|
58
|
+
).fetch
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def url
|
63
|
+
@url ||= api_url_for(endpoint)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def api_url_for(endpoint)
|
69
|
+
path = ENDPOINTS[endpoint] || raise(ApiError, "Unknown endpoint #{endpoint}")
|
70
|
+
"#{API_URL}#{path}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def uri
|
74
|
+
URI(url)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module FavroApi
|
2
|
+
class Response
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
attr_accessor :response, :entities, :page, :limit, :pages, :request_id
|
6
|
+
|
7
|
+
def_delegators :response, :status, :body
|
8
|
+
|
9
|
+
def initialize(opts = {})
|
10
|
+
self.response = opts.delete(:response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def error?
|
14
|
+
status >= 400
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse(type: nil)
|
18
|
+
self.entities =
|
19
|
+
if type
|
20
|
+
type.send(:parse, parsed_response['entities'])
|
21
|
+
else
|
22
|
+
parsed_response['entities']
|
23
|
+
end
|
24
|
+
self.pages = parsed_response['pages']
|
25
|
+
self.page = parsed_response['page']
|
26
|
+
self.limit = parsed_response['limit']
|
27
|
+
self.request_id = parsed_response['requestId']
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def parsed_response
|
32
|
+
@parsed_response ||= JSON.parse(body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def backend_identifier
|
36
|
+
response.headers['x-favro-backend-identifier']
|
37
|
+
end
|
38
|
+
|
39
|
+
def ratelimit
|
40
|
+
{
|
41
|
+
limit: response.headers['x-ratelimit-limit'].to_i,
|
42
|
+
remaining: response.headers['x-ratelimit-remaining'].to_i,
|
43
|
+
reset: Time.parse(response.headers['x-ratelimit-reset'])
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/favro_api.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
require_relative './favro_api/version'
|
5
|
+
require_relative './favro_api/auth'
|
6
|
+
require_relative './favro_api/driver'
|
7
|
+
|
8
|
+
module FavroApi
|
9
|
+
class ApiError < StandardError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :auth, :organization_id
|
13
|
+
|
14
|
+
def auth=(params = {})
|
15
|
+
@auth = Auth.new(params[:email], params[:token])
|
16
|
+
end
|
17
|
+
|
18
|
+
def driver
|
19
|
+
Driver.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(meth, *args)
|
23
|
+
if driver.respond_to? meth
|
24
|
+
return driver.public_send meth, *args
|
25
|
+
end
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: favro_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.9'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Besedin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-12 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.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Written in ruby
|
70
|
+
email:
|
71
|
+
- kr3ssh@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- favro_api.gemspec
|
86
|
+
- lib/favro_api.rb
|
87
|
+
- lib/favro_api/auth.rb
|
88
|
+
- lib/favro_api/data_types.rb
|
89
|
+
- lib/favro_api/data_types/assignment.rb
|
90
|
+
- lib/favro_api/data_types/base.rb
|
91
|
+
- lib/favro_api/data_types/card.rb
|
92
|
+
- lib/favro_api/data_types/collection.rb
|
93
|
+
- lib/favro_api/data_types/column.rb
|
94
|
+
- lib/favro_api/data_types/comment.rb
|
95
|
+
- lib/favro_api/data_types/custom_field.rb
|
96
|
+
- lib/favro_api/data_types/organization.rb
|
97
|
+
- lib/favro_api/data_types/shared_to_user.rb
|
98
|
+
- lib/favro_api/data_types/tag.rb
|
99
|
+
- lib/favro_api/data_types/task.rb
|
100
|
+
- lib/favro_api/data_types/tasklist.rb
|
101
|
+
- lib/favro_api/data_types/user.rb
|
102
|
+
- lib/favro_api/data_types/widget.rb
|
103
|
+
- lib/favro_api/driver.rb
|
104
|
+
- lib/favro_api/fields.rb
|
105
|
+
- lib/favro_api/parser.rb
|
106
|
+
- lib/favro_api/request.rb
|
107
|
+
- lib/favro_api/response.rb
|
108
|
+
- lib/favro_api/version.rb
|
109
|
+
homepage: https://github.com/kressh/favro_api
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.5.1
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Favro API
|
133
|
+
test_files: []
|