basecamp 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -33,9 +33,19 @@ Include the system gems and require the library in your script
33
33
  == Establishing a Connection
34
34
 
35
35
  The first thing you need to do is establish a connection to Basecamp. This
36
- requires your Basecamp site address and your login credentials. Example:
36
+ requires your Basecamp site address and your login credentials or API token.
37
37
 
38
- Basecamp.establish_connection!('you.grouphub.com', 'username', 'password')
38
+ === Using username and password
39
+
40
+ Basecamp.establish_connection!('yoururl.basecamphq.com', 'username', 'password')
41
+
42
+ === Using API token (My Info -> Show your tokens)
43
+
44
+ Basecamp.establish_connection!('yoururl.basecamphq.com', 'APITOKEN', 'X')
45
+
46
+ === With a Basecamp account that use SSL (https://yoururl.basecamphq.com)
47
+
48
+ Basecamp.establish_connection!('yoururl.basecamphq.com', 'APITOKEN', 'X', true)
39
49
 
40
50
  This is the same whether you're accessing using the ActiveResource interface,
41
51
  or the legacy interface.
@@ -127,14 +137,19 @@ you want to delete. Example:
127
137
  If the resource accepts file attachments, the +attachments+ parameter should
128
138
  be an array of Basecamp::Attachment objects. Example:
129
139
 
130
- a1 = Basecamp::Attachment.create('primary', File.read('primary.doc'))
131
- a2 = Basecamp::Attachment.create('another', File.read('another.doc'))
140
+ f1 = File.open('primary.doc')
141
+ s1 = StringIO.new('a string')
142
+
143
+ a1 = Basecamp::Attachment.create('primary', f1)
144
+ a2 = Basecamp::Attachment.create('another', s1))
132
145
 
133
146
  m = Basecamp::Message.new(:project_id => 1037)
134
147
  ...
135
148
  m.attachments = [a1, a2]
136
149
  m.save # => true
137
150
 
151
+ f1.close
152
+
138
153
  === Milestones
139
154
 
140
155
  Is not implemented as an active resource, it uses the non-REST interface.
@@ -145,6 +160,24 @@ For example, to list all milestones in a project:
145
160
  milestones = Basecamp::Milestone.list(1037)
146
161
  milestones.first.title # => "The Milestone"
147
162
 
163
+ === More about Todo Items
164
+
165
+ To access all todo items in a todo list:
166
+
167
+ Basecamp::TodoItem.find(:all, :params => { :todo_list_id => 3422 })
168
+
169
+ You can't access all todo items in a project with a single API call.
170
+ So you have to do something like this:
171
+
172
+ def todo_items_on_project(project_id)
173
+ todo_items = []
174
+ todo_lists = TodoList.find(:all, :params => { :project_id => project_id })
175
+ todo_lists.each do |todo_list|
176
+ todo_items += TodoItem.find(:all, :params => { :todo_list_id => todo_list.id })
177
+ end
178
+ todo_items
179
+ end
180
+
148
181
  = Using the non-REST interface
149
182
 
150
183
  You can access other resources not included in this wrapper yet using "record" and "records".
@@ -155,9 +188,17 @@ You can access other resources not included in this wrapper yet using "record" a
155
188
  people_in_company = Basecamp.records("person", "/contacts/people/85")
156
189
  people_in_company.first.first_name # => "Jason"
157
190
 
191
+ = Using json as the default format
192
+
193
+ By default the wrapper will use :xml for the active record connection but you can set :json as the default format:
194
+
195
+ Basecamp.establish_connection!('yoururl.basecamphq.com', 'APITOKEN', 'X', true, false)
196
+
197
+ Note: We recommend using xml. There are some API calls that don't behave well with json.
198
+
158
199
  == Contributors
159
200
 
160
201
  * jamesarosen
161
202
  * defeated
162
203
  * justinbarry
163
- * fmiopensource
204
+ * fmiopensource
data/lib/basecamp/base.rb CHANGED
@@ -3,15 +3,17 @@ module Basecamp
3
3
  attr_accessor :use_xml
4
4
  attr_reader :site, :user, :password, :use_ssl
5
5
 
6
- def establish_connection!(site, user, password, use_ssl = false)
6
+ def establish_connection!(site, user, password, use_ssl = false, use_xml = true)
7
7
  @site = site
8
8
  @user = user
9
9
  @password = password
10
10
  @use_ssl = use_ssl
11
+ @use_xml = use_xml
11
12
 
12
- Resource.user = user
13
+ Resource.user = user
13
14
  Resource.password = password
14
- Resource.site = (use_ssl ? "https" : "http") + "://" + site
15
+ Resource.site = (use_ssl ? "https" : "http") + "://" + site
16
+ Resource.format = (use_xml ? :xml : :json)
15
17
 
16
18
  @connection = Connection.new(self)
17
19
  end
@@ -6,10 +6,12 @@ module Basecamp; class Connection
6
6
  @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE if master.use_ssl
7
7
  end
8
8
 
9
- def post(path, body, headers = {})
9
+ def post(path, iostream, headers = {})
10
10
  request = Net::HTTP::Post.new(path, headers.merge('Accept' => 'application/xml'))
11
11
  request.basic_auth(@master.user, @master.password)
12
- @connection.request(request, body)
12
+ request.body_stream = iostream
13
+ request.content_length = iostream.size
14
+ @connection.request(request)
13
15
  end
14
16
 
15
17
  def get(path, headers = {})
@@ -17,4 +19,4 @@ module Basecamp; class Connection
17
19
  request.basic_auth(@master.user, @master.password)
18
20
  @connection.request(request)
19
21
  end
20
- end; end
22
+ end; end
@@ -16,6 +16,9 @@ module Basecamp; class Resource < ActiveResource::Base
16
16
  end
17
17
  end
18
18
 
19
+ def check_prefix_options(options)
20
+ end
21
+
19
22
  def prefix(options = {})
20
23
  if options.any?
21
24
  options.map { |name, value| "/#{name.to_s.chomp('_id').pluralize}/#{value}" }.join + '/'
@@ -23,9 +26,21 @@ module Basecamp; class Resource < ActiveResource::Base
23
26
  '/'
24
27
  end
25
28
  end
29
+
30
+ def all(options = {})
31
+ find(:all, options)
32
+ end
33
+
34
+ def first(options = {})
35
+ find(:first, options)
36
+ end
37
+
38
+ def last(options = {})
39
+ find(:last, options)
40
+ end
26
41
  end
27
42
 
28
43
  def prefix_options
29
44
  id ? {} : super
30
45
  end
31
- end; end
46
+ end; end
@@ -1,5 +1,5 @@
1
1
  module Basecamp; class Attachment
2
- attr_accessor :id, :filename, :content
2
+ attr_accessor :id, :filename, :content, :category_id
3
3
 
4
4
  def self.create(filename, content)
5
5
  returning new(filename, content) do |attachment|
@@ -16,7 +16,7 @@ module Basecamp; class Attachment
16
16
  end
17
17
 
18
18
  def to_xml(options = {})
19
- { :file => attributes }.to_xml(options)
19
+ { :file => attributes, :category_id => category_id }.to_xml(options)
20
20
  end
21
21
 
22
22
  def inspect
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
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: 2011-05-12 00:00:00 -03:00
19
+ date: 2011-11-23 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
+ name: oauth2
23
24
  prerelease: false
24
- type: :runtime
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
@@ -31,11 +31,11 @@ dependencies:
31
31
  segments:
32
32
  - 0
33
33
  version: "0"
34
- name: oauth2
34
+ type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
+ name: xml-simple
37
38
  prerelease: false
38
- type: :runtime
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
@@ -45,11 +45,11 @@ dependencies:
45
45
  segments:
46
46
  - 0
47
47
  version: "0"
48
- name: xml-simple
48
+ type: :runtime
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency
51
+ name: activeresource
51
52
  prerelease: false
52
- type: :runtime
53
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
@@ -61,11 +61,11 @@ dependencies:
61
61
  - 3
62
62
  - 0
63
63
  version: 2.3.0
64
- name: activeresource
64
+ type: :runtime
65
65
  version_requirements: *id003
66
66
  - !ruby/object:Gem::Dependency
67
+ name: rake
67
68
  prerelease: false
68
- type: :development
69
69
  requirement: &id004 !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements:
@@ -75,11 +75,11 @@ dependencies:
75
75
  segments:
76
76
  - 0
77
77
  version: "0"
78
- name: rake
78
+ type: :development
79
79
  version_requirements: *id004
80
80
  - !ruby/object:Gem::Dependency
81
+ name: mg
81
82
  prerelease: false
82
- type: :development
83
83
  requirement: &id005 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
@@ -91,11 +91,11 @@ dependencies:
91
91
  - 0
92
92
  - 8
93
93
  version: 0.0.8
94
- name: mg
94
+ type: :development
95
95
  version_requirements: *id005
96
96
  - !ruby/object:Gem::Dependency
97
+ name: rspec
97
98
  prerelease: false
98
- type: :development
99
99
  requirement: &id006 !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
@@ -107,11 +107,11 @@ dependencies:
107
107
  - 3
108
108
  - 0
109
109
  version: 1.3.0
110
- name: rspec
110
+ type: :development
111
111
  version_requirements: *id006
112
112
  - !ruby/object:Gem::Dependency
113
+ name: webmock
113
114
  prerelease: false
114
- type: :development
115
115
  requirement: &id007 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
@@ -123,7 +123,7 @@ dependencies:
123
123
  - 2
124
124
  - 2
125
125
  version: 1.2.2
126
- name: webmock
126
+ type: :development
127
127
  version_requirements: *id007
128
128
  description: Basecamp API wrapper.
129
129
  email: nobody@gmail.com