logan 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logan/HashConstructed.rb +11 -3
- data/lib/logan/client.rb +12 -0
- data/lib/logan/person.rb +0 -4
- data/lib/logan/project.rb +19 -2
- data/lib/logan/todolist.rb +23 -0
- 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: e39f8bb1bebade7a2d6d7b2ef6f8149e02cee606
|
4
|
+
data.tar.gz: d0c5e113b5db76d6b8cf8f9a03a64f27d562539a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 584042077954e3131935bc73b96a95a28dc0875bb29b635036780ba1bf2accbeb3cd7943bc62347dec472f0db8985f98d28de0b9fc27c38b68a6df36c48bf866
|
7
|
+
data.tar.gz: f71fc834f95e02da617cd974c78daf932a8d90f0a5f6c24ea6a5f6b17ead66cbf0ea922b047dbd6cb90ee10bfce9c237032de6e70228ba61896e85ba5918ea6c
|
@@ -1,5 +1,13 @@
|
|
1
|
+
# this module is taken from the accepted answer here
|
2
|
+
# http://stackoverflow.com/questions/1572660/is-there-a-way-to-initialize-an-object-through-a-hash
|
3
|
+
|
1
4
|
module HashConstructed
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
+
|
6
|
+
# initalizes the object by pulling key-value pairs from the hash and
|
7
|
+
# mapping them to the object's instance variables
|
8
|
+
#
|
9
|
+
# @param [Hash] h hash containing key-value pairs to map to object instance variables
|
10
|
+
def initialize(h)
|
11
|
+
h.each { |k,v| send("#{k}=",v) if respond_to?("#{k}=") }
|
12
|
+
end
|
5
13
|
end
|
data/lib/logan/client.rb
CHANGED
@@ -4,17 +4,29 @@ module Logan
|
|
4
4
|
class Client
|
5
5
|
include HTTParty
|
6
6
|
|
7
|
+
# Initializes the Logan shared client with information required to communicate with Basecamp
|
8
|
+
#
|
9
|
+
# @param basecamp_id [String] the Basecamp company ID
|
10
|
+
# @param username [String] the username to use for requests
|
11
|
+
# @param password [String] the password to use for the passed username
|
12
|
+
# @param user_agent [String] the user-agent string to include in header of requests
|
7
13
|
def initialize(basecamp_id, username, password, user_agent)
|
8
14
|
self.class.base_uri "https://basecamp.com/#{basecamp_id}/api/v1"
|
9
15
|
self.class.basic_auth username, password
|
10
16
|
self.class.headers 'User-Agent' => user_agent
|
11
17
|
end
|
12
18
|
|
19
|
+
# get projects from Basecamp API
|
20
|
+
#
|
21
|
+
# @return [Array<Logan::Project>] array of {Logan::Project} instances
|
13
22
|
def projects
|
14
23
|
response = self.class.get '/projects.json'
|
15
24
|
response.parsed_response.map { |h| p = Logan::Project.new(h) }
|
16
25
|
end
|
17
26
|
|
27
|
+
# get active Todo lists for all projects from Basecamp API
|
28
|
+
#
|
29
|
+
# @return [Array<Logan::TodoList>] array of {Logan::TodoList} instances
|
18
30
|
def todolists
|
19
31
|
response = self.class.get '/todolists.json'
|
20
32
|
|
data/lib/logan/person.rb
CHANGED
data/lib/logan/project.rb
CHANGED
@@ -8,6 +8,9 @@ module Logan
|
|
8
8
|
attr_accessor :id
|
9
9
|
attr_accessor :name
|
10
10
|
|
11
|
+
# get active todo lists for this project from Basecamp API
|
12
|
+
#
|
13
|
+
# @return [Array<Logan::TodoList>] array of active todo lists for this project
|
11
14
|
def todolists
|
12
15
|
active_response = Logan::Client.get "/projects/#{@id}/todolists.json"
|
13
16
|
lists_array = active_response.parsed_response.map do |h|
|
@@ -15,6 +18,9 @@ module Logan
|
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
21
|
+
# get completed todo lists for this project from Basecamp API
|
22
|
+
#
|
23
|
+
# @return [Array<Logan::TodoList>] array of completed todo lists for this project
|
18
24
|
def completed_todolists
|
19
25
|
completed_response = Logan::Client.get "/projects/#{@id}/todolists/completed.json"
|
20
26
|
lists_array = completed_response.parsed_response.map do |h|
|
@@ -22,18 +28,29 @@ module Logan
|
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
31
|
+
# get both active and completed todo lists for this project from Basecamp API
|
32
|
+
#
|
33
|
+
# @return [Array<Logan::TodoList>] array of active and completed todo lists for this project
|
25
34
|
def all_todolists
|
26
35
|
todolists + completed_todolists
|
27
36
|
end
|
28
37
|
|
38
|
+
# get an individual todo list for this project from Basecamp API
|
39
|
+
#
|
40
|
+
# @param [String] list_id id for the todo list
|
41
|
+
# @return [Logan::TodoList] todo list instance
|
29
42
|
def todolist(list_id)
|
30
43
|
response = Logan::Client.get "/projects/#{@id}/todolists/#{list_id}.json"
|
31
44
|
Logan::TodoList.new response.parsed_response.merge({ :project_id => @id })
|
32
45
|
end
|
33
46
|
|
34
|
-
|
47
|
+
# create a todo list in this project via Basecamp API
|
48
|
+
#
|
49
|
+
# @param [Logan::TodoList] todo_list todo list instance to be created
|
50
|
+
# @return [Logan::TodoList] todo list instance from Basecamp API response
|
51
|
+
def create_todolist(todo_list)
|
35
52
|
post_params = {
|
36
|
-
:body =>
|
53
|
+
:body => todo_list.post_json,
|
37
54
|
:headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
|
38
55
|
}
|
39
56
|
|
data/lib/logan/todolist.rb
CHANGED
@@ -14,6 +14,8 @@ module Logan
|
|
14
14
|
attr_accessor :completed_todos
|
15
15
|
attr_accessor :url
|
16
16
|
|
17
|
+
# intializes a todo list by calling the HashConstructed initialize method and
|
18
|
+
# setting both @remaining_todos and @completed_todos to empty arrays
|
17
19
|
def initialize(h)
|
18
20
|
@remaining_todos = []
|
19
21
|
@completed_todos = []
|
@@ -24,16 +26,29 @@ module Logan
|
|
24
26
|
{ :name => @name, :description => @description }.to_json
|
25
27
|
end
|
26
28
|
|
29
|
+
# assigns the {#remaining_todos} and {#completed_todos} from the associated keys
|
30
|
+
# in the passed hash
|
31
|
+
#
|
32
|
+
# @param [Hash] todo_hash hash possibly containing todos under 'remaining' and 'completed' keys
|
27
33
|
def todos=(todo_hash)
|
28
34
|
@remaining_todos = todo_hash['remaining'].map { |h| Logan::Todo.new h }
|
29
35
|
@completed_todos = todo_hash['completed'].map { |h| Logan::Todo.new h }
|
36
|
+
return nil
|
30
37
|
end
|
31
38
|
|
39
|
+
# searches the remaining and completed todos for the first todo with the substring in its content
|
40
|
+
#
|
41
|
+
# @param [String] substring substring to look for
|
42
|
+
# @return [Logan::Todo] the matched todo, or nil if there wasn't one
|
32
43
|
def todo_with_substring(substring)
|
33
44
|
issue_todo = @remaining_todos.detect{ |t| !t.content.index(substring).nil? }
|
34
45
|
issue_todo ||= @completed_todos.detect { |t| !t.content.index(substring).nil? }
|
35
46
|
end
|
36
47
|
|
48
|
+
# create a todo in this todo list via the Basecamp API
|
49
|
+
#
|
50
|
+
# @param [Logan::Todo] todo the todo instance to create in this todo lost
|
51
|
+
# @return [Logan::Todo] the created todo returned from the Basecamp API
|
37
52
|
def create_todo(todo)
|
38
53
|
post_params = {
|
39
54
|
:body => todo.post_json,
|
@@ -44,6 +59,10 @@ module Logan
|
|
44
59
|
Logan::Todo.new response
|
45
60
|
end
|
46
61
|
|
62
|
+
# update a todo in this todo list via the Basecamp API
|
63
|
+
#
|
64
|
+
# @param [Logan::Todo] todo the todo instance to update in this todo list
|
65
|
+
# @return [Logan::Todo] the updated todo instance returned from the Basecamp API
|
47
66
|
def update_todo(todo)
|
48
67
|
put_params = {
|
49
68
|
:body => todo.put_json,
|
@@ -54,6 +73,10 @@ module Logan
|
|
54
73
|
Logan::Todo.new response
|
55
74
|
end
|
56
75
|
|
76
|
+
# delete a todo in this todo list via delete call to Basecamp API
|
77
|
+
#
|
78
|
+
# @param [Logan::Todo] todo the todo instance to be delete from this todo list
|
79
|
+
# @return [HTTParty::response] response from Basecamp for delete request
|
57
80
|
def delete_todo(todo)
|
58
81
|
response = Logan::Client.delete "/projects/#{@project_id}/todos/#{todo.id}.json"
|
59
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Birarda
|
@@ -48,3 +48,4 @@ signing_key:
|
|
48
48
|
specification_version: 4
|
49
49
|
summary: ruby gem to communicate with new Basecamp API
|
50
50
|
test_files: []
|
51
|
+
has_rdoc:
|