timestamp_api 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/timestamp_api.rb +5 -2
- data/lib/timestamp_api/model_default_api_methods.rb +4 -4
- data/lib/timestamp_api/model_relations.rb +5 -1
- data/lib/timestamp_api/models/client.rb +1 -1
- data/lib/timestamp_api/models/project.rb +1 -1
- data/lib/timestamp_api/models/task.rb +13 -0
- data/lib/timestamp_api/utils.rb +5 -1
- data/lib/timestamp_api/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eda86ccc06685b3025de57778e18b1943e0f134
|
4
|
+
data.tar.gz: 939a0532a3315cef11d210ef6e538c9c1ec2f17f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df9a1a1057a2669dcaa5c236541ac01e56b50dbb741c287151e5c60e6ae2d04726bd322d2e97f80983fd3a4d1e8afd2527d9075f155d0161da09137944de42d7
|
7
|
+
data.tar.gz: d762cc2172b2ed7884302fc5de2137a33ab34e0f5b47f7473123b77488766a00e6c4640a30f6dcb7ba75049fb62c7d460f6c161bca0857a3dbf300ba7bc28cc7
|
data/README.md
CHANGED
@@ -125,14 +125,16 @@ There's also a `bin/console` executable provided with this gem, if you want a RE
|
|
125
125
|
|
126
126
|
### What's implemented already ?
|
127
127
|
|
128
|
-
* [x] `Project
|
129
|
-
* [x] `
|
128
|
+
* [x] `Project` model
|
129
|
+
* [x] `Client` model
|
130
|
+
* [x] `Task` model
|
130
131
|
* [x] `belongs_to` relationships
|
131
132
|
|
132
133
|
### What's not implemented yet ?
|
133
134
|
|
134
135
|
* [ ] _all other models_ :scream:
|
135
136
|
* [ ] `has_many` relationships
|
137
|
+
* [ ] document and integrate [Inch-CI](https://inch-ci.org)
|
136
138
|
|
137
139
|
## Development
|
138
140
|
|
data/lib/timestamp_api.rb
CHANGED
@@ -13,8 +13,11 @@ require "timestamp_api/model"
|
|
13
13
|
require "timestamp_api/collection"
|
14
14
|
require "timestamp_api/models/project"
|
15
15
|
require "timestamp_api/models/client"
|
16
|
+
require "timestamp_api/models/task"
|
16
17
|
|
17
18
|
module TimestampAPI
|
19
|
+
extend Utils
|
20
|
+
|
18
21
|
@api_endpoint = "https://api.ontimestamp.com/api"
|
19
22
|
|
20
23
|
class << self
|
@@ -22,8 +25,8 @@ module TimestampAPI
|
|
22
25
|
end
|
23
26
|
|
24
27
|
def self.request(method, path, query_params = {})
|
25
|
-
output(method, path, query_params) if verbose
|
26
|
-
response = RestClient::Request.execute(request_options(method, path, query_params))
|
28
|
+
output(method, path, camelize_keys(query_params)) if verbose
|
29
|
+
response = RestClient::Request.execute(request_options(method, path, camelize_keys(query_params)))
|
27
30
|
modelify(JSON.parse(response))
|
28
31
|
rescue RestClient::Forbidden
|
29
32
|
raise InvalidAPIKey
|
@@ -14,15 +14,15 @@ module TimestampAPI
|
|
14
14
|
path.nil? ? self.class_variable_get(:@@api_path) : self.class_variable_set(:@@api_path, path)
|
15
15
|
end
|
16
16
|
|
17
|
-
def all
|
17
|
+
def all(query_params = {})
|
18
18
|
raise APIPathNotSet.new(self) if api_path.nil?
|
19
|
-
TimestampAPI.request(:get, api_path)
|
19
|
+
TimestampAPI.request(:get, api_path, query_params)
|
20
20
|
end
|
21
21
|
|
22
|
-
def find(id)
|
22
|
+
def find(id, query_params = {})
|
23
23
|
return nil if id.nil?
|
24
24
|
raise APIPathNotSet.new(self) if api_path.nil?
|
25
|
-
TimestampAPI.request(:get, "#{api_path}/#{id}")
|
25
|
+
TimestampAPI.request(:get, "#{api_path}/#{id}", query_params)
|
26
26
|
rescue RestClient::ResourceNotFound
|
27
27
|
raise ResourceNotFound.new(self, id)
|
28
28
|
end
|
@@ -5,7 +5,11 @@ module TimestampAPI
|
|
5
5
|
base.class_eval do
|
6
6
|
after_initialize do
|
7
7
|
self.class.class_variable_get(:@@belongs_to).each do |association_name|
|
8
|
-
|
8
|
+
if json_data.has_key? camelize("#{association_name}_id") # e.g. "projectId" in tasks
|
9
|
+
instance_variable_set(:"@_#{association_name}_id", json_data[camelize("#{association_name}_id")])
|
10
|
+
elsif json_data.has_key? camelize(association_name) # e.g. "client" hash with "id" item in projects
|
11
|
+
instance_variable_set(:"@_#{association_name}_id", json_data[camelize(association_name)]["id"])
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
11
15
|
|
@@ -2,6 +2,6 @@ module TimestampAPI
|
|
2
2
|
class Client < Model
|
3
3
|
api_path "/clients"
|
4
4
|
|
5
|
-
has_attributes :id, :created_at, :updated_at, :
|
5
|
+
has_attributes :id, :created_at, :updated_at, :name, :code, :is_archived, :is_account_default
|
6
6
|
end
|
7
7
|
end
|
@@ -2,7 +2,7 @@ module TimestampAPI
|
|
2
2
|
class Project < Model
|
3
3
|
api_path "/projects"
|
4
4
|
|
5
|
-
has_attributes :id, :created_at, :updated_at, :
|
5
|
+
has_attributes :id, :created_at, :updated_at, :name, :code, :color, :initiation_date,
|
6
6
|
:target_completion_date, :is_archived, :is_billable, :is_public, :is_approvable
|
7
7
|
|
8
8
|
belongs_to :client
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module TimestampAPI
|
2
|
+
class Task < Model
|
3
|
+
api_path "/tasks"
|
4
|
+
|
5
|
+
has_attributes :id, :created_at, :updated_at, :name, :is_archived, :is_billable
|
6
|
+
|
7
|
+
belongs_to :project
|
8
|
+
|
9
|
+
def self.for_project_id(project_id)
|
10
|
+
all(project_id: project_id)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/timestamp_api/utils.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
module TimestampAPI
|
2
2
|
module Utils
|
3
3
|
def camelize(symbol)
|
4
|
-
symbol.to_s.split('_').each_with_index.map{ |chunk, idx| idx == 0 ? chunk : chunk.capitalize }.join
|
4
|
+
symbol.to_s.split('_').each_with_index.map{ |chunk, idx| idx == 0 ? chunk : chunk.capitalize }.join.gsub(/^\w/, &:downcase)
|
5
|
+
end
|
6
|
+
|
7
|
+
def camelize_keys(hash)
|
8
|
+
hash.each_with_object({}) { |pair, acc| acc[camelize(pair[0])] = pair[1] }
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timestamp_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Baudino
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- lib/timestamp_api/model_relations.rb
|
167
167
|
- lib/timestamp_api/models/client.rb
|
168
168
|
- lib/timestamp_api/models/project.rb
|
169
|
+
- lib/timestamp_api/models/task.rb
|
169
170
|
- lib/timestamp_api/utils.rb
|
170
171
|
- lib/timestamp_api/version.rb
|
171
172
|
- timestamp_api.gemspec
|