productive 0.2.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 +7 -0
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/lib/generators/productive/productive_generator.rb +31 -0
- data/lib/json_api_paginator.rb +64 -0
- data/lib/productive.rb +22 -0
- data/lib/productive/configuration.rb +17 -0
- data/lib/productive/railtie.rb +9 -0
- data/lib/productive/resources/base.rb +10 -0
- data/lib/productive/resources/client.rb +4 -0
- data/lib/productive/resources/person.rb +4 -0
- data/lib/productive/resources/project.rb +7 -0
- data/lib/productive/version.rb +3 -0
- data/productive.gemspec +17 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6bbda2ba26520dea3d18c61ee5dad955d1cff23
|
4
|
+
data.tar.gz: c548d9825ab20b7b2c4add3abc57a697a418841b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c92f9cad758a6f5d0287edd37b72515ec8d7dfd0b127ada6f5193b0ae4d31772aa38c3d23507c9a99084b68a94f6393a1cab985101ebfd83c5ec8de04acf852e
|
7
|
+
data.tar.gz: 8e61f057da799703f68bd46c4f9074f6158f9482b1e07d8b4aa6f28efef8f77b0ba0eebaf7d881d2c7e0b4969c4edff6b8f139cad85eda940f1e08415fb54c38
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Josip Bišćan
|
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,68 @@
|
|
1
|
+
# Productive API client
|
2
|
+
|
3
|
+
Productive API client is a gem based on [JsonApiClient](https://github.com/chingor13/json_api_client). It provides resource classes for resources available in Productive API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Include the gem in your Gemfile
|
8
|
+
```ruby
|
9
|
+
gem 'productive'
|
10
|
+
```
|
11
|
+
|
12
|
+
Bundle the Gemfile
|
13
|
+
```ruby
|
14
|
+
bundle install
|
15
|
+
```
|
16
|
+
|
17
|
+
## Initialize
|
18
|
+
|
19
|
+
If you're using the gem in Rails project, run:
|
20
|
+
```ruby
|
21
|
+
rails generate productive API_KEY ACCOUNT_ID
|
22
|
+
```
|
23
|
+
which will generate ```config/initializers/productive.rb``` initializer, setting up your `API_KEY` and `ACCOUNT ID`.
|
24
|
+
|
25
|
+
If you're using the gem in a standalone project, you need to configure the `API_KEY` and `ACCOUNT_ID` and setup the `Productive::Base` resource class:
|
26
|
+
```ruby
|
27
|
+
Productive.configure do |config|
|
28
|
+
config.api_key = ENV['productive_api_key']
|
29
|
+
config.account_id = ACCOUNT_ID
|
30
|
+
end
|
31
|
+
|
32
|
+
Productive::Base.setup
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
For every resource available in Productive API, there is a resource class available for use similar to an `ActiveRecord` class.
|
38
|
+
|
39
|
+
Some examples:
|
40
|
+
```ruby
|
41
|
+
Productive::Project.all
|
42
|
+
Productive::Project.paginate(per_page: 50).page(5).find
|
43
|
+
|
44
|
+
Productive::Project.where(client_id: 1).all
|
45
|
+
```
|
46
|
+
|
47
|
+
## Customizing
|
48
|
+
|
49
|
+
This gem uses a custom `JsonApiPaginator` based on the one available in `JsonApiClient`. If you need a different paginator, you can pass it as a configuration option:
|
50
|
+
```ruby
|
51
|
+
Productive.configure do |config|
|
52
|
+
config.paginator = MyCustomPaginator
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
By default, this gem utilises the Productive API available at https://productive.io/api/v2/, but if you need to use a different endpoint, you can pass that as a configuration option:
|
57
|
+
```ruby
|
58
|
+
Productive.configure do |config|
|
59
|
+
config.base_url = 'http://productive.dev/api/v2/'
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
## Credits
|
64
|
+
Productive API client is maintained by [Productive](https://productive.io).and sponsored by [Infinum](https://infinum.co).
|
65
|
+
|
66
|
+
## License
|
67
|
+
Copyright © 2016 Productive, Infinum.
|
68
|
+
Productive API client is free software, and may be redistributed under the terms specified in the LICENSE file.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
class ProductiveGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :api_key, required: true, desc: 'required'
|
7
|
+
argument :account_id, required: true, desc: 'required'
|
8
|
+
|
9
|
+
gem 'productive'
|
10
|
+
|
11
|
+
desc 'Configure Productive API client'
|
12
|
+
|
13
|
+
def create_initializer_file
|
14
|
+
unless /^[a-f0-9\-]{36}$/ =~ api_key
|
15
|
+
raise Thor::Error, "Invalid Productive API key #{api_key.inspect}\nYou can find the API key on the Settings -> Security page of https://productive.io"
|
16
|
+
end
|
17
|
+
|
18
|
+
unless /^[0-9]*$/ =~ account_id
|
19
|
+
raise Thor::Error, "Invalid Productive Account ID #{account_id.inspect}\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
initializer 'productive.rb' do
|
23
|
+
<<-EOF
|
24
|
+
Productive.configure do |config|
|
25
|
+
config.api_key = #{api_key.inspect}
|
26
|
+
config.account_id = #{account_id.inspect}
|
27
|
+
end
|
28
|
+
EOF
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class JsonApiPaginator
|
2
|
+
attr_reader :params, :result_set, :links, :meta
|
3
|
+
|
4
|
+
def initialize(result_set, data)
|
5
|
+
@params = params_for_uri(result_set.uri)
|
6
|
+
@result_set = result_set
|
7
|
+
@links = data['links']
|
8
|
+
@meta = data['meta']
|
9
|
+
end
|
10
|
+
|
11
|
+
def next
|
12
|
+
links['next'] ? result_set.links.fetch_link('next') : nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def prev
|
16
|
+
links['prev'] ? result_set.links.fetch_link('prev') : nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def first
|
20
|
+
links['first'] ? result_set.links.fetch_link('first') : nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def last
|
24
|
+
links['last'] ? result_set.links.fetch_link('last') : nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def total_pages
|
28
|
+
if links['last']
|
29
|
+
uri = result_set.links.link_url_for('last')
|
30
|
+
last_params = params_for_uri(uri)
|
31
|
+
last_params['page[number]'].to_i
|
32
|
+
else
|
33
|
+
current_page
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def total_entries
|
38
|
+
meta['total_count'].to_i || per_page * total_pages
|
39
|
+
end
|
40
|
+
alias_method :total_count, :total_entries
|
41
|
+
|
42
|
+
def per_page
|
43
|
+
params['page[size]'].to_i
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_page
|
47
|
+
(params['page[number]'] || 1).to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def previous_page
|
51
|
+
current_page > 1 ? (current_page - 1) : nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def next_page
|
55
|
+
current_page < total_pages ? (current_page + 1) : nil
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def params_for_uri(uri)
|
60
|
+
return {} unless uri
|
61
|
+
uri = Addressable::URI.parse(uri)
|
62
|
+
uri.query_values || {}
|
63
|
+
end
|
64
|
+
end
|
data/lib/productive.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'json_api_client'
|
2
|
+
|
3
|
+
require 'productive/version'
|
4
|
+
require 'productive/configuration'
|
5
|
+
require 'productive/resources/base'
|
6
|
+
require 'productive/resources/client'
|
7
|
+
require 'productive/resources/person'
|
8
|
+
require 'productive/resources/project'
|
9
|
+
|
10
|
+
require 'productive/railtie' if defined?(Rails::Railtie)
|
11
|
+
|
12
|
+
module Productive
|
13
|
+
class << self
|
14
|
+
def configure
|
15
|
+
yield configuration
|
16
|
+
end
|
17
|
+
|
18
|
+
def configuration
|
19
|
+
@configuration ||= Productive::Configuration.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'json_api_paginator'
|
2
|
+
|
3
|
+
module Productive
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :api_key
|
6
|
+
attr_accessor :account_id
|
7
|
+
attr_accessor :base_url
|
8
|
+
attr_accessor :paginator
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.api_key = ENV['PRODUCTIVE_API_KEY']
|
12
|
+
self.account_id = nil
|
13
|
+
self.base_url = 'https://productive.io/api/v2/'
|
14
|
+
self.paginator = JsonApiPaginator
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Productive
|
2
|
+
class Base < JsonApiClient::Resource
|
3
|
+
def self.setup
|
4
|
+
config = Productive.configuration
|
5
|
+
self.site = File.join config.base_url, config.account_id.to_s, '/'
|
6
|
+
self.connection_options = {headers: {'X-Auth-Token' => config.api_key}}
|
7
|
+
self.paginator = config.paginator
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/productive.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require 'productive/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'productive'
|
6
|
+
s.version = Productive::VERSION.dup
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.summary = 'A JSONAPI-based client to consume Productive API'
|
9
|
+
s.homepage = 'https://github.com/infinum/productive_api_client'
|
10
|
+
s.description = 'Productive API client'
|
11
|
+
s.authors = ['Josip Bišćan']
|
12
|
+
s.email = 'josip@infinum.hr'
|
13
|
+
s.license = 'MIT'
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
|
16
|
+
s.add_dependency 'json_api_client'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: productive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josip Bišćan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json_api_client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Productive API client
|
28
|
+
email: josip@infinum.hr
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE.txt
|
36
|
+
- README.md
|
37
|
+
- lib/generators/productive/productive_generator.rb
|
38
|
+
- lib/json_api_paginator.rb
|
39
|
+
- lib/productive.rb
|
40
|
+
- lib/productive/configuration.rb
|
41
|
+
- lib/productive/railtie.rb
|
42
|
+
- lib/productive/resources/base.rb
|
43
|
+
- lib/productive/resources/client.rb
|
44
|
+
- lib/productive/resources/person.rb
|
45
|
+
- lib/productive/resources/project.rb
|
46
|
+
- lib/productive/version.rb
|
47
|
+
- productive.gemspec
|
48
|
+
homepage: https://github.com/infinum/productive_api_client
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.5.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: A JSONAPI-based client to consume Productive API
|
72
|
+
test_files: []
|