basecamp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +134 -0
  2. data/lib/basecamp.rb +4 -145
  3. metadata +50 -22
  4. data/readme +0 -13
data/README.rdoc ADDED
@@ -0,0 +1,134 @@
1
+ = A Ruby library for working with the Basecamp web-services API.
2
+
3
+ For more information about the Basecamp web-services API, visit:
4
+
5
+ http://developer.37signals.com/basecamp
6
+
7
+ You can find the original code in:
8
+
9
+ http://developer.37signals.com/basecamp/basecamp.rb
10
+
11
+ NOTE: not all of Basecamp's web-services are accessible via REST. This
12
+ library provides access to RESTful services via ActiveResource. Services not
13
+ yet upgraded to REST are accessed via the Basecamp class. Continue reading
14
+ for more details.
15
+
16
+ == Installation
17
+
18
+ gem install basecamp
19
+
20
+ == Establishing a Connection
21
+
22
+ The first thing you need to do is establish a connection to Basecamp. This
23
+ requires your Basecamp site address and your login credentials. Example:
24
+
25
+ Basecamp.establish_connection!('you.grouphub.com', 'username', 'password')
26
+
27
+ This is the same whether you're accessing using the ActiveResource interface,
28
+ or the legacy interface.
29
+
30
+ == Getting API token
31
+
32
+ If you only have username/password you can get the API token to use in future calls.
33
+
34
+ Basecamp.establish_connection!('you.grouphub.com', 'username', 'password')
35
+ Basecamp.get_token
36
+
37
+ == Using the REST interface via ActiveResource
38
+
39
+ The REST interface is accessed via ActiveResource, a popular Ruby library
40
+ that implements object-relational mapping for REST web-services. For more
41
+ information on working with ActiveResource, see:
42
+
43
+ * http://api.rubyonrails.org/files/activeresource/README.html
44
+ * http://api.rubyonrails.org/classes/ActiveResource/Base.html
45
+
46
+
47
+ === Finding a Resource
48
+
49
+ Find a specific resource using the +find+ method. Attributes of the resource
50
+ are available as instance methods on the resulting object. For example, to
51
+ find a message with the ID of 8675309 and access its title attribute, you
52
+ would do the following:
53
+
54
+ m = Basecamp::Message.find(8675309)
55
+ m.title # => 'Jenny'
56
+
57
+ To find all messages for a given project, use find(:all), passing the
58
+ project_id as a parameter to find. Example:
59
+
60
+ messages = Basecamp::Message.find(:all, params => { :project_id => 1037 })
61
+ messages.size # => 25
62
+
63
+
64
+ === Creating a Resource
65
+
66
+ Create a resource by making a new instance of that resource, setting its
67
+ attributes, and saving it. If the resource requires a prefix to identify
68
+ it (as is the case with resources that belong to a sub-resource, such as a
69
+ project), it should be specified when instantiating the object. Examples:
70
+
71
+ m = Basecamp::Message.new(:project_id => 1037)
72
+ m.category_id = 7301
73
+ m.title = 'Message in a bottle'
74
+ m.body = 'Another lonely day, with no one here but me'
75
+ m.save # => true
76
+
77
+ c = Basecamp::Comment.new(:post_id => 25874)
78
+ c.body = 'Did you get those TPS reports?'
79
+ c.save # => true
80
+
81
+ You can also create a resource using the +create+ method, which will create
82
+ and save it in one step. Example:
83
+
84
+ Basecamp::TodoItem.create(:todo_list_id => 3422, :contents => 'Do it')
85
+
86
+
87
+ === Updating a Resource
88
+
89
+ To update a resource, first find it by its id, change its attributes, and
90
+ save it. Example:
91
+
92
+ m = Basecamp::Message.find(8675309)
93
+ m.body = 'Changed'
94
+ m.save # => true
95
+
96
+
97
+ === Deleting a Resource
98
+
99
+ To delete a resource, use the +delete+ method with the ID of the resource
100
+ you want to delete. Example:
101
+
102
+ Basecamp::Message.delete(1037)
103
+
104
+
105
+ === Attaching Files to a Resource
106
+
107
+ If the resource accepts file attachments, the +attachments+ parameter should
108
+ be an array of Basecamp::Attachment objects. Example:
109
+
110
+ a1 = Basecamp::Attachment.create('primary', File.read('primary.doc'))
111
+ a2 = Basecamp::Attachment.create('another', File.read('another.doc'))
112
+
113
+ m = Basecamp::Message.new(:project_id => 1037)
114
+ ...
115
+ m.attachments = [a1, a2]
116
+ m.save # => true
117
+
118
+
119
+ = Using the non-REST inteface
120
+
121
+ The non-REST interface is accessed via instance methods on the Basecamp
122
+ class. Ensure you've established a connection, then create a new Basecamp
123
+ instance and call methods on it. Object attributes are accessible as methods.
124
+ Example:
125
+
126
+ session = Basecamp.new
127
+ person = session.person(93832) # => #<Record(person)..>
128
+ person.first_name # => "Jason"
129
+
130
+ == Contributors
131
+
132
+ * jamesarosen
133
+ * defeated
134
+ * justinbarry
data/lib/basecamp.rb CHANGED
@@ -3,151 +3,7 @@ require 'yaml'
3
3
  require 'date'
4
4
  require 'time'
5
5
 
6
- begin
7
- require 'xmlsimple'
8
- rescue LoadError
9
- begin
10
- require 'rubygems'
11
- require 'xmlsimple'
12
- rescue LoadError
13
- abort <<-ERROR
14
- The 'xml-simple' library could not be loaded. If you have RubyGems installed
15
- you can install xml-simple by doing "gem install xml-simple".
16
- ERROR
17
- end
18
- end
19
-
20
- begin
21
- require 'activeresource'
22
- rescue LoadError
23
- begin
24
- require 'rubygems'
25
- require 'activeresource'
26
- rescue LoadError
27
- abort <<-ERROR
28
- The 'activeresource' library could not be loaded. If you have RubyGems
29
- installed you can install ActiveResource by doing "gem install activeresource".
30
- ERROR
31
- end
32
- end
33
-
34
- # = A Ruby library for working with the Basecamp web-services API.
35
- #
36
- # For more information about the Basecamp web-services API, visit:
37
- #
38
- # http://developer.37signals.com/basecamp
39
- #
40
- # NOTE: not all of Basecamp's web-services are accessible via REST. This
41
- # library provides access to RESTful services via ActiveResource. Services not
42
- # yet upgraded to REST are accessed via the Basecamp class. Continue reading
43
- # for more details.
44
- #
45
- #
46
- # == Establishing a Connection
47
- #
48
- # The first thing you need to do is establish a connection to Basecamp. This
49
- # requires your Basecamp site address and your login credentials. Example:
50
- #
51
- # Basecamp.establish_connection!('you.grouphub.com', 'username', 'password')
52
- #
53
- # This is the same whether you're accessing using the ActiveResource interface,
54
- # or the legacy interface.
55
- #
56
- #
57
- # == Using the REST interface via ActiveResource
58
- #
59
- # The REST interface is accessed via ActiveResource, a popular Ruby library
60
- # that implements object-relational mapping for REST web-services. For more
61
- # information on working with ActiveResource, see:
62
- #
63
- # * http://api.rubyonrails.org/files/activeresource/README.html
64
- # * http://api.rubyonrails.org/classes/ActiveResource/Base.html
65
- #
66
- #
67
- # === Finding a Resource
68
- #
69
- # Find a specific resource using the +find+ method. Attributes of the resource
70
- # are available as instance methods on the resulting object. For example, to
71
- # find a message with the ID of 8675309 and access its title attribute, you
72
- # would do the following:
73
- #
74
- # m = Basecamp::Message.find(8675309)
75
- # m.title # => 'Jenny'
76
- #
77
- # To find all messages for a given project, use find(:all), passing the
78
- # project_id as a parameter to find. Example:
79
- #
80
- # messages = Basecamp::Message.find(:all, params => { :project_id => 1037 })
81
- # messages.size # => 25
82
- #
83
- #
84
- # === Creating a Resource
85
- #
86
- # Create a resource by making a new instance of that resource, setting its
87
- # attributes, and saving it. If the resource requires a prefix to identify
88
- # it (as is the case with resources that belong to a sub-resource, such as a
89
- # project), it should be specified when instantiating the object. Examples:
90
- #
91
- # m = Basecamp::Message.new(:project_id => 1037)
92
- # m.category_id = 7301
93
- # m.title = 'Message in a bottle'
94
- # m.body = 'Another lonely day, with no one here but me'
95
- # m.save # => true
96
- #
97
- # c = Basecamp::Comment.new(:post_id => 25874)
98
- # c.body = 'Did you get those TPS reports?'
99
- # c.save # => true
100
- #
101
- # You can also create a resource using the +create+ method, which will create
102
- # and save it in one step. Example:
103
- #
104
- # Basecamp::TodoItem.create(:todo_list_id => 3422, :contents => 'Do it')
105
- #
106
- #
107
- # === Updating a Resource
108
- #
109
- # To update a resource, first find it by its id, change its attributes, and
110
- # save it. Example:
111
- #
112
- # m = Basecamp::Message.find(8675309)
113
- # m.body = 'Changed'
114
- # m.save # => true
115
- #
116
- #
117
- # === Deleting a Resource
118
- #
119
- # To delete a resource, use the +delete+ method with the ID of the resource
120
- # you want to delete. Example:
121
- #
122
- # Basecamp::Message.delete(1037)
123
- #
124
- #
125
- # === Attaching Files to a Resource
126
- #
127
- # If the resource accepts file attachments, the +attachments+ parameter should
128
- # be an array of Basecamp::Attachment objects. Example:
129
- #
130
- # a1 = Basecamp::Attachment.create('primary', File.read('primary.doc'))
131
- # a2 = Basecamp::Attachment.create('another', File.read('another.doc'))
132
- #
133
- # m = Basecamp::Message.new(:project_id => 1037)
134
- # ...
135
- # m.attachments = [a1, a2]
136
- # m.save # => true
137
- #
138
- #
139
- # = Using the non-REST inteface
140
- #
141
- # The non-REST interface is accessed via instance methods on the Basecamp
142
- # class. Ensure you've established a connection, then create a new Basecamp
143
- # instance and call methods on it. Object attributes are accessible as methods.
144
- # Example:
145
- #
146
- # session = Basecamp.new
147
- # person = session.person(93832) # => #<Record(person)..>
148
- # person.first_name # => "Jason"
149
- #
150
- class Basecamp
6
+ module Basecamp
151
7
  class Connection #:nodoc:
152
8
  def initialize(master)
153
9
  @master = master
@@ -202,6 +58,9 @@ class Basecamp
202
58
  end
203
59
 
204
60
  class Project < Resource
61
+ def time_entries(options = {})
62
+ @time_entries ||= TimeEntry.find(:all, :params => options.merge(:project_id => id))
63
+ end
205
64
  end
206
65
 
207
66
  class Company < Resource
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basecamp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 25
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Anibal Cucco
@@ -16,12 +16,12 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-06-15 00:00:00 -04:00
19
+ date: 2011-05-10 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- name: oauth2
24
23
  prerelease: false
24
+ type: :runtime
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
@@ -33,11 +33,11 @@ dependencies:
33
33
  - 0
34
34
  - 8
35
35
  version: 0.0.8
36
- type: :runtime
36
+ name: oauth2
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency
39
- name: rake
40
39
  prerelease: false
40
+ type: :runtime
41
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
@@ -47,12 +47,40 @@ dependencies:
47
47
  segments:
48
48
  - 0
49
49
  version: "0"
50
- type: :development
50
+ name: xml-simple
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
- name: mg
54
53
  prerelease: false
54
+ type: :runtime
55
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ name: activerecord
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ prerelease: false
68
+ type: :development
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ name: rake
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ prerelease: false
82
+ type: :development
83
+ requirement: &id005 !ruby/object:Gem::Requirement
56
84
  none: false
57
85
  requirements:
58
86
  - - ~>
@@ -63,12 +91,12 @@ dependencies:
63
91
  - 0
64
92
  - 8
65
93
  version: 0.0.8
66
- type: :development
67
- version_requirements: *id003
94
+ name: mg
95
+ version_requirements: *id005
68
96
  - !ruby/object:Gem::Dependency
69
- name: rspec
70
97
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
98
+ type: :development
99
+ requirement: &id006 !ruby/object:Gem::Requirement
72
100
  none: false
73
101
  requirements:
74
102
  - - ~>
@@ -79,12 +107,12 @@ dependencies:
79
107
  - 3
80
108
  - 0
81
109
  version: 1.3.0
82
- type: :development
83
- version_requirements: *id004
110
+ name: rspec
111
+ version_requirements: *id006
84
112
  - !ruby/object:Gem::Dependency
85
- name: webmock
86
113
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
114
+ type: :development
115
+ requirement: &id007 !ruby/object:Gem::Requirement
88
116
  none: false
89
117
  requirements:
90
118
  - - ~>
@@ -95,8 +123,8 @@ dependencies:
95
123
  - 2
96
124
  - 2
97
125
  version: 1.2.2
98
- type: :development
99
- version_requirements: *id005
126
+ name: webmock
127
+ version_requirements: *id007
100
128
  description: Basecamp API wrapper.
101
129
  email: nobody@gmail.com
102
130
  executables: []
@@ -107,7 +135,7 @@ extra_rdoc_files: []
107
135
 
108
136
  files:
109
137
  - lib/basecamp.rb
110
- - readme
138
+ - README.rdoc
111
139
  has_rdoc: true
112
140
  homepage: http://github.com/anibalcucco/basecamp-wrapper
113
141
  licenses: []
@@ -138,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
166
  requirements: []
139
167
 
140
168
  rubyforge_project:
141
- rubygems_version: 1.3.7
169
+ rubygems_version: 1.5.3
142
170
  signing_key:
143
171
  specification_version: 3
144
172
  summary: Basecamp API wrapper.
data/readme DELETED
@@ -1,13 +0,0 @@
1
- = Using the Basecamp API with Ruby
2
-
3
- This is the basecamp wrapper provided by 37Signals to access their API with a little change to obtain the API token.
4
-
5
- This is useful when you only have username/password and you want to obtain the token automatically to use that in future calls.
6
-
7
- = Usage
8
-
9
- >> Basecamp.establish_connection!('<subdomain>.basecamphq.com', <username>, <password>, true)
10
- >> Basecamp.get_token
11
- => "the token"
12
-
13
- -- Anibal Cucco