logan 0.0.9 → 0.1.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 +4 -4
- data/lib/logan/client.rb +26 -26
- data/lib/logan/errors.rb +28 -0
- data/lib/logan/response_handler.rb +23 -0
- data/lib/logan.rb +3 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd4e95b42c7d708e8d8b11a93afe0c65aedc1e12
|
4
|
+
data.tar.gz: aa891ac5706e4d2cb58543ea4f33ee67a891512d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19c3d366443abf9573cfa8def7ae49dca190ef345585fedd4391061aa97a8e0e871b7121d6313d9dd396aca517837b7a828cf17038f80a7f655517ccf4eda635
|
7
|
+
data.tar.gz: 018fdb52e55f5606d2e281d9a7efa942999b02d19f0ca5e4848aa5a1d46fc8a33c51511eb8cfe4c2d48b0a5203683638a862213f7a32aa0b75a083134923e7bd
|
data/lib/logan/client.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'logan/project'
|
2
|
-
|
2
|
+
require 'logan/response_handler'
|
3
3
|
module Logan
|
4
4
|
class Client
|
5
5
|
include HTTParty
|
6
|
-
|
6
|
+
include ResponseHandler
|
7
|
+
|
7
8
|
# Initializes the Logan shared client with information required to communicate with Basecamp
|
8
9
|
#
|
9
10
|
# @param basecamp_id [String] the Basecamp company ID
|
@@ -14,68 +15,67 @@ module Logan
|
|
14
15
|
self.class.headers 'User-Agent' => user_agent
|
15
16
|
self.auth = auth_hash
|
16
17
|
end
|
17
|
-
|
18
|
+
|
18
19
|
# Updates authorization information for Logan shared client
|
19
|
-
#
|
20
|
+
#
|
20
21
|
# @param auth_hash [Hash] authorization hash consisting of a username and password combination (:username, :password) or an access_token (:access_token)
|
21
22
|
def auth=(auth_hash)
|
22
23
|
# symbolize the keys
|
23
24
|
new_auth_hash = {}
|
24
25
|
auth_hash.each {|k, v| new_auth_hash[k.to_sym] = v}
|
25
26
|
auth_hash = new_auth_hash
|
26
|
-
|
27
|
+
|
27
28
|
if auth_hash.has_key? :access_token
|
28
29
|
# clear the basic_auth, if it's set
|
29
30
|
self.class.default_options.reject!{ |k| k == :basic_auth }
|
30
|
-
|
31
|
+
|
31
32
|
# set the Authorization headers
|
32
33
|
self.class.headers.merge!("Authorization" => "Bearer #{auth_hash[:access_token]}")
|
33
34
|
elsif auth_hash.has_key?(:username) && auth_hash.has_key?(:password)
|
34
35
|
self.class.basic_auth auth_hash[:username], auth_hash[:password]
|
35
|
-
|
36
|
+
|
36
37
|
# remove the access_token from the headers, if it exists
|
37
38
|
self.class.headers.reject!{ |k, v| k == "Authorization" }
|
38
39
|
else
|
39
40
|
raise """
|
40
|
-
Incomplete authorization information passed in authorization hash.
|
41
|
+
Incomplete authorization information passed in authorization hash.
|
41
42
|
You must have either an :access_token or a username password combination (:username, :password).
|
42
43
|
"""
|
43
44
|
end
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
# get projects from Basecamp API
|
47
|
-
#
|
48
|
+
#
|
48
49
|
# @return [Array<Logan::Project>] array of {Logan::Project} instances
|
49
50
|
def projects
|
50
51
|
response = self.class.get '/projects.json'
|
51
|
-
response.
|
52
|
+
handle_response(response, Proc.new {|h| Logan::Project.new(h) })
|
52
53
|
end
|
53
|
-
|
54
|
+
|
54
55
|
# get active Todo lists for all projects from Basecamp API
|
55
|
-
#
|
56
|
+
#
|
56
57
|
# @return [Array<Logan::TodoList>] array of {Logan::TodoList} instances
|
57
58
|
def todolists
|
58
59
|
response = self.class.get '/todolists.json'
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
60
|
+
handle_response(response,
|
61
|
+
Proc.new { |h|
|
62
|
+
list = Logan::TodoList.new(h)
|
63
|
+
# grab the project ID for this list from the url
|
64
|
+
list.project_id = list.url.scan( /projects\/(\d+)/).last.first
|
65
|
+
# return the list so this method returns an array of lists
|
66
|
+
return list
|
67
|
+
}
|
68
|
+
)
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def events(since_time, page = 1)
|
72
72
|
response = self.class.get "/events.json?since=#{since_time.to_s}&page=#{page}"
|
73
|
-
response.
|
73
|
+
handle_response(response, Proc.new {|h| Logan::Event.new(h) })
|
74
74
|
end
|
75
75
|
|
76
76
|
def people
|
77
77
|
response = self.class.get "/people.json"
|
78
|
-
response.
|
78
|
+
handle_response(response, Proc.new {|h| Logan::Person.new(h) })
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
data/lib/logan/errors.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Logan
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :code
|
4
|
+
attr_reader :message
|
5
|
+
|
6
|
+
def initialize(code, message)
|
7
|
+
@code = code.to_sym
|
8
|
+
@message = message
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_json
|
12
|
+
JSON.generate({error: @code.to_s, error_description: @message})
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class AccessDeniedError < Error
|
18
|
+
def initialize
|
19
|
+
super :access_denied, "You are not allowed to access this resource."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class InvalidRequestError < Error
|
24
|
+
def initialize
|
25
|
+
super :invalid_request, "The request has wrong parameters."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Logan
|
2
|
+
module ResponseHandler
|
3
|
+
def handle_response(response, block)
|
4
|
+
if success?(response.response)
|
5
|
+
response.parsed_response.map { |h| block.call(h) }
|
6
|
+
else
|
7
|
+
handle_error(response.response)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def handle_error(response)
|
12
|
+
if response.kind_of? Net::HTTPUnauthorized
|
13
|
+
raise Logan::AccessDeniedError
|
14
|
+
else
|
15
|
+
raise Logan::InvalidRequestError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def success?(response)
|
20
|
+
response.kind_of? Net::HTTPSuccess
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/logan.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Birarda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -76,9 +76,11 @@ files:
|
|
76
76
|
- lib/logan/HashConstructed.rb
|
77
77
|
- lib/logan/client.rb
|
78
78
|
- lib/logan/comment.rb
|
79
|
+
- lib/logan/errors.rb
|
79
80
|
- lib/logan/event.rb
|
80
81
|
- lib/logan/person.rb
|
81
82
|
- lib/logan/project.rb
|
83
|
+
- lib/logan/response_handler.rb
|
82
84
|
- lib/logan/todo.rb
|
83
85
|
- lib/logan/todolist.rb
|
84
86
|
homepage: https://github.com/birarda/logan
|
@@ -93,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
95
|
requirements:
|
94
96
|
- - ">="
|
95
97
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
98
|
+
version: 1.8.7
|
97
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
100
|
requirements:
|
99
101
|
- - ">="
|