granary 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.travis.yml +9 -0
- data/Gemfile +3 -0
- data/LICENSE +7 -0
- data/README +16 -0
- data/Rakefile +1 -0
- data/granary.gemspec +26 -0
- data/lib/faraday/symbolize_keys_for_json.rb +5 -0
- data/lib/granary/time_entry.rb +12 -0
- data/lib/granary/version.rb +3 -0
- data/lib/granary.rb +45 -0
- data/spec/granary/time_entry_spec.rb +14 -0
- data/spec/spec_helper.rb +2 -0
- metadata +155 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012 Y. Thong Kuah, YouDo Limited
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Granary
|
2
|
+
|
3
|
+
A Ruby wrapper for the Harvest API
|
4
|
+
|
5
|
+
Early days yet...
|
6
|
+
|
7
|
+
api = Granary::API.new(:authorization => 'YOUR HARVEST AUTH', :subdomain => 'YOUR HARVEST SUBDOMAIN')
|
8
|
+
|
9
|
+
project_id = 'THE ID OF A HARVEST PROJECT'
|
10
|
+
from_date = Date.civil(2012, 2, 6).strftime("%Y%m%d") # Monday
|
11
|
+
to_date = Date.civil(2012, 2, 10).strftime("%Y%m%d") # Friday
|
12
|
+
|
13
|
+
time_entries = api.project_time(project_id, from_date, to_date) # this will fetch all time for the project for the date range specified
|
14
|
+
tt = time_entries.map {|t| Granary::TimeEntry.new t[:day_entry] } # Wrap it into handy object
|
15
|
+
|
16
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/granary.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "granary/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "granary"
|
7
|
+
s.version = Granary::VERSION
|
8
|
+
s.authors = ["Thong Kuah", "YouDo Limited"]
|
9
|
+
s.email = ["kuahyeow@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/kuahyeow/granary"
|
11
|
+
s.summary = "A Ruby libary for the Harvest API"
|
12
|
+
s.description = "A Ruby libary for the Harvest API"
|
13
|
+
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency "rspec", "~> 2.8"
|
21
|
+
s.add_development_dependency "webmock", "~> 1.7"
|
22
|
+
|
23
|
+
s.add_runtime_dependency "faraday", "~> 0.7.6"
|
24
|
+
s.add_runtime_dependency "faraday-stack", "~> 0.1.4"
|
25
|
+
s.add_runtime_dependency "yajl-ruby"
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Granary
|
2
|
+
class TimeEntry
|
3
|
+
API_FIELDS = [:spent_at, :hours, :notes, :id, :project_id, :task_id, :user_id]
|
4
|
+
API_FIELDS.each {|field| attr_accessor field}
|
5
|
+
|
6
|
+
def initialize(fields = {})
|
7
|
+
API_FIELDS.each do |accessor|
|
8
|
+
send "#{accessor}=", fields[accessor]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/granary.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_stack'
|
3
|
+
|
4
|
+
Dir[File.expand_path('../faraday/*.rb', __FILE__)].each{|f| require f}
|
5
|
+
require File.expand_path('../granary/time_entry', __FILE__)
|
6
|
+
|
7
|
+
module Granary
|
8
|
+
module Connection
|
9
|
+
def connection(root, authorization)
|
10
|
+
Faraday.new(:url => root, :headers => {:accept => 'application/json', :authorization => authorization}) do |builder|
|
11
|
+
builder.use FaradayStack::ResponseJSON, :content_type => 'application/json'
|
12
|
+
builder.use Faraday::Request::JSON # encode request params as json
|
13
|
+
builder.use Faraday::Response::Logger # log the request to STDOUT
|
14
|
+
builder.use Faraday::Response::RaiseError # raise exceptions on 40x, 50x responses
|
15
|
+
builder.use Faraday::Adapter::NetHttp # make http requests with Net::HTTP
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
class API
|
22
|
+
include Connection
|
23
|
+
|
24
|
+
attr_accessor :subdomain
|
25
|
+
|
26
|
+
def initialize(options = {})
|
27
|
+
@authorization = options[:authorization]
|
28
|
+
@subdomain = options[:subdomain]
|
29
|
+
end
|
30
|
+
|
31
|
+
def project_time(project_id, from_date, to_date)
|
32
|
+
response = get "/projects/#{project_id}/entries?from=#{from_date}&to=#{to_date}"
|
33
|
+
response.body
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
def get(url)
|
38
|
+
root = "https://#{subdomain}.harvestapp.com"
|
39
|
+
connection(root, @authorization).get url
|
40
|
+
rescue Faraday::Error
|
41
|
+
raise
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Granary::TimeEntry do
|
4
|
+
it "should initialize" do
|
5
|
+
time_entry = Granary::TimeEntry.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should initialize with typical fields" do
|
9
|
+
time_entry = Granary::TimeEntry.new(:spent_at => "2011-01-01", :hours => 5.1, :notes => "Writing this gem")
|
10
|
+
time_entry.spent_at.should == "2011-01-01"
|
11
|
+
time_entry.hours.should == 5.1
|
12
|
+
time_entry.notes.should == "Writing this gem"
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: granary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Thong Kuah
|
14
|
+
- YouDo Limited
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2012-02-10 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 19
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 8
|
33
|
+
version: "2.8"
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: webmock
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 1
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 7
|
48
|
+
version: "1.7"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: faraday
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 15
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 7
|
63
|
+
- 6
|
64
|
+
version: 0.7.6
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: faraday-stack
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 19
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
- 1
|
79
|
+
- 4
|
80
|
+
version: 0.1.4
|
81
|
+
type: :runtime
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yajl-ruby
|
85
|
+
prerelease: false
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
type: :runtime
|
96
|
+
version_requirements: *id005
|
97
|
+
description: A Ruby libary for the Harvest API
|
98
|
+
email:
|
99
|
+
- kuahyeow@gmail.com
|
100
|
+
executables: []
|
101
|
+
|
102
|
+
extensions: []
|
103
|
+
|
104
|
+
extra_rdoc_files: []
|
105
|
+
|
106
|
+
files:
|
107
|
+
- .gitignore
|
108
|
+
- .travis.yml
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE
|
111
|
+
- README
|
112
|
+
- Rakefile
|
113
|
+
- granary.gemspec
|
114
|
+
- lib/faraday/symbolize_keys_for_json.rb
|
115
|
+
- lib/granary.rb
|
116
|
+
- lib/granary/time_entry.rb
|
117
|
+
- lib/granary/version.rb
|
118
|
+
- spec/granary/time_entry_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
homepage: https://github.com/kuahyeow/granary
|
121
|
+
licenses: []
|
122
|
+
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 3
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
requirements: []
|
147
|
+
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 1.8.6
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: A Ruby libary for the Harvest API
|
153
|
+
test_files:
|
154
|
+
- spec/granary/time_entry_spec.rb
|
155
|
+
- spec/spec_helper.rb
|