idonethis-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +13 -0
- data/idonethis-client.gemspec +31 -0
- data/lib/idonethis.rb +29 -0
- data/lib/idonethis/client.rb +67 -0
- data/lib/idonethis/configuration.rb +35 -0
- data/lib/idonethis/connection.rb +20 -0
- data/lib/idonethis/error.rb +5 -0
- data/lib/idonethis/middleware.rb +21 -0
- data/lib/idonethis/models/done.rb +7 -0
- data/lib/idonethis/version.rb +3 -0
- data/spec/idonethis/models/done_spec.rb +11 -0
- data/spec/spec_helper.rb +15 -0
- metadata +215 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bob Breznak
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# IDoneThis Client
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'idonethis-client'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install idonethis-client
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
# require the gem
|
20
|
+
require 'idonethis'
|
21
|
+
|
22
|
+
# set global configurations for all spawned clients
|
23
|
+
IDoneThis.configure do |c|
|
24
|
+
c.username = 'bob@brez.io' # your username
|
25
|
+
c.password = 'some-password' # your password
|
26
|
+
c.team = 'myteam' # your team's name
|
27
|
+
end
|
28
|
+
|
29
|
+
# and get a client
|
30
|
+
client = IDoneThis.client
|
31
|
+
|
32
|
+
# or....
|
33
|
+
|
34
|
+
# just set the credientals for an individual client
|
35
|
+
creds = { username: 'bob@brez.io',
|
36
|
+
password: 'some-password',
|
37
|
+
team: 'my-team' }
|
38
|
+
client.login creds
|
39
|
+
|
40
|
+
# then get the list of dones for the team
|
41
|
+
|
42
|
+
# from some date to today
|
43
|
+
client.dones '2013-01-01'
|
44
|
+
|
45
|
+
# or some range of dates
|
46
|
+
client.dones '2013-01-01', '2013-02-01'
|
47
|
+
|
48
|
+
## TODO
|
49
|
+
|
50
|
+
* Expand iDoneThis service coverage
|
51
|
+
* More testing
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
1. Fork it
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'idonethis/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "idonethis-client"
|
8
|
+
spec.version = IDoneThis::VERSION
|
9
|
+
spec.authors = ["Bob Breznak"]
|
10
|
+
spec.email = ["bob.breznak@gmail.com"]
|
11
|
+
spec.description = %q{A simple client for connecting with and getting data iDoneThis.}
|
12
|
+
spec.summary = %q{A hackygem that connects to iDoneThis}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "hashie", "~> 2.0.4"
|
22
|
+
spec.add_dependency "faraday", "~> 0.8.7"
|
23
|
+
spec.add_dependency "faraday-cookie_jar", "~> 0.0.3"
|
24
|
+
spec.add_dependency "nokogiri", "~> 1.5.9"
|
25
|
+
spec.add_dependency "faraday_middleware", "~> 0.9.0"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec", '~> 2.5'
|
30
|
+
spec.add_development_dependency "simplecov", "~> 0.7.1"
|
31
|
+
end
|
data/lib/idonethis.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday-cookie_jar'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
|
6
|
+
require File.expand_path('../version', __FILE__)
|
7
|
+
require File.expand_path('../idonethis/error', __FILE__)
|
8
|
+
require File.expand_path('../idonethis/configuration', __FILE__)
|
9
|
+
require File.expand_path('../idonethis/client', __FILE__)
|
10
|
+
require File.expand_path('../idonethis/middleware', __FILE__)
|
11
|
+
require File.expand_path('../idonethis/models/done', __FILE__)
|
12
|
+
|
13
|
+
module IDoneThis
|
14
|
+
extend Configuration
|
15
|
+
|
16
|
+
def self.client(options={})
|
17
|
+
IDoneThis::Client.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.method_missing(method, *args, &block)
|
21
|
+
return super unless client.respond_to?(method)
|
22
|
+
client.send(method, *args, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.respond_to?(method)
|
26
|
+
return client.respond_to?(method) || super
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
require File.expand_path('../connection', __FILE__)
|
4
|
+
|
5
|
+
module IDoneThis
|
6
|
+
class Client
|
7
|
+
|
8
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
9
|
+
|
10
|
+
def initialize(options={})
|
11
|
+
options = IDoneThis.options.merge(options)
|
12
|
+
|
13
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
14
|
+
send("#{key}=", options[key])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def login
|
19
|
+
begin
|
20
|
+
self.login!
|
21
|
+
rescue
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def login!
|
29
|
+
base = base_connection
|
30
|
+
|
31
|
+
login_form = base.get('https://idonethis.com/accounts/login/')
|
32
|
+
login_html = Nokogiri::HTML(login_form.body)
|
33
|
+
login_csrf = login_html.search('form input[@name=csrfmiddlewaretoken]').first["value"]
|
34
|
+
|
35
|
+
login_creds = { username: self.username, password: self.password, csrfmiddlewaretoken: login_csrf}
|
36
|
+
|
37
|
+
login_resp = base.post do |request|
|
38
|
+
request.url 'https://idonethis.com/accounts/login/'
|
39
|
+
request.headers['Referer'] = 'https://idonethis.com/accounts/login/'
|
40
|
+
request.body = login_creds
|
41
|
+
end
|
42
|
+
|
43
|
+
raise ServiceError.new('Unable to login') if login_resp.status != 302
|
44
|
+
|
45
|
+
self.connection = base
|
46
|
+
self.connection.url_prefix = URI("https://idonethis.com/api/v3/team/#{self.team}/")
|
47
|
+
|
48
|
+
login_resp
|
49
|
+
end
|
50
|
+
|
51
|
+
def get(path)
|
52
|
+
req = self.connection.get(path)
|
53
|
+
raise StandardError.new(req.body) unless req.status == 200
|
54
|
+
req.body
|
55
|
+
end
|
56
|
+
|
57
|
+
def dones(start_date, end_date=nil)
|
58
|
+
start_date = Date.parse(start_date.to_s)
|
59
|
+
end_date = Date.parse((end_date || Date.today).to_s)
|
60
|
+
|
61
|
+
self.get "dones/?start=#{start_date.to_s}&end=#{end_date.to_s}"
|
62
|
+
end
|
63
|
+
|
64
|
+
include Connection
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module IDoneThis
|
2
|
+
module Configuration
|
3
|
+
VALID_OPTIONS_KEYS = [
|
4
|
+
:username,
|
5
|
+
:password,
|
6
|
+
:team
|
7
|
+
].freeze
|
8
|
+
|
9
|
+
DEFAULT_USERNAME = nil
|
10
|
+
DEFAULT_PASSWORD = nil
|
11
|
+
DEFAULT_TEAM = nil
|
12
|
+
|
13
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
14
|
+
|
15
|
+
def self.extended(base)
|
16
|
+
base.reset
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
|
23
|
+
def options
|
24
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
25
|
+
option.merge!(key => send(key))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def reset
|
30
|
+
self.username = DEFAULT_USERNAME
|
31
|
+
self.password = DEFAULT_PASSWORD
|
32
|
+
self.team = DEFAULT_TEAM
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module IDoneThis
|
2
|
+
module Connection
|
3
|
+
|
4
|
+
attr_accessor :connection
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def base_connection
|
9
|
+
|
10
|
+
|
11
|
+
Faraday::Connection.new do |connection|
|
12
|
+
connection.use Faraday::Request::UrlEncoded
|
13
|
+
connection.use :cookie_jar
|
14
|
+
connection.response :idonethis
|
15
|
+
connection.response :json, :content_type => /\bjson$/
|
16
|
+
connection.adapter Faraday.default_adapter
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module IDoneThis
|
2
|
+
class Middleware < Faraday::Response::Middleware
|
3
|
+
def call(env)
|
4
|
+
@app.call(env).on_complete do |env|
|
5
|
+
on_complete(env)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(app)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_complete(env)
|
14
|
+
if env[:url].path.match(/dones\/$/)
|
15
|
+
env[:body].map!{|done_hash| Done.new(done_hash) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Faraday.register_middleware :response, :idonethis => IDoneThis::Middleware
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
|
9
|
+
require 'idonethis'
|
10
|
+
require 'rspec'
|
11
|
+
require 'rspec/autorun'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: idonethis-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bob Breznak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hashie
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.8.7
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.7
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: faraday-cookie_jar
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.0.3
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: nokogiri
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.5.9
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.5.9
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: faraday_middleware
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.9.0
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.9.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: bundler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.3'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.3'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '2.5'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '2.5'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: simplecov
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 0.7.1
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 0.7.1
|
158
|
+
description: A simple client for connecting with and getting data iDoneThis.
|
159
|
+
email:
|
160
|
+
- bob.breznak@gmail.com
|
161
|
+
executables: []
|
162
|
+
extensions: []
|
163
|
+
extra_rdoc_files: []
|
164
|
+
files:
|
165
|
+
- .gitignore
|
166
|
+
- .rspec
|
167
|
+
- Gemfile
|
168
|
+
- LICENSE.txt
|
169
|
+
- README.md
|
170
|
+
- Rakefile
|
171
|
+
- idonethis-client.gemspec
|
172
|
+
- lib/idonethis.rb
|
173
|
+
- lib/idonethis/client.rb
|
174
|
+
- lib/idonethis/configuration.rb
|
175
|
+
- lib/idonethis/connection.rb
|
176
|
+
- lib/idonethis/error.rb
|
177
|
+
- lib/idonethis/middleware.rb
|
178
|
+
- lib/idonethis/models/done.rb
|
179
|
+
- lib/idonethis/version.rb
|
180
|
+
- spec/idonethis/models/done_spec.rb
|
181
|
+
- spec/spec_helper.rb
|
182
|
+
homepage: ''
|
183
|
+
licenses:
|
184
|
+
- MIT
|
185
|
+
post_install_message:
|
186
|
+
rdoc_options: []
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
none: false
|
191
|
+
requirements:
|
192
|
+
- - ! '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
segments:
|
196
|
+
- 0
|
197
|
+
hash: 1292588170158978654
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
|
+
none: false
|
200
|
+
requirements:
|
201
|
+
- - ! '>='
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
segments:
|
205
|
+
- 0
|
206
|
+
hash: 1292588170158978654
|
207
|
+
requirements: []
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 1.8.23
|
210
|
+
signing_key:
|
211
|
+
specification_version: 3
|
212
|
+
summary: A hackygem that connects to iDoneThis
|
213
|
+
test_files:
|
214
|
+
- spec/idonethis/models/done_spec.rb
|
215
|
+
- spec/spec_helper.rb
|