ruby-trello 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/trello.rb CHANGED
@@ -60,6 +60,7 @@ module Trello
60
60
  autoload :Request, 'trello/net'
61
61
  autoload :TInternet, 'trello/net'
62
62
  autoload :Token, 'trello/token'
63
+ autoload :Webhook, 'trello/webhook'
63
64
 
64
65
  module Authorization
65
66
  autoload :AuthPolicy, 'trello/authorization'
@@ -6,6 +6,9 @@ module Trello
6
6
  @owner = owner
7
7
  @target = target
8
8
  @options = {}
9
+ if target.is_a?(Array)
10
+ target.each{|array_element| array_element.client = owner.client}
11
+ end
9
12
  end
10
13
  end
11
14
  end
data/lib/trello/token.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Trello
2
2
  class Token < BasicData
3
- register_attributes :id, :member_id, :created_at, :permissions,
4
- :readonly => [ :id, :member_id, :created_at, :permissions ]
3
+ register_attributes :id, :member_id, :created_at, :permissions, :webhooks,
4
+ :readonly => [ :id, :member_id, :created_at, :permissions, :webhooks ]
5
5
 
6
6
  class << self
7
7
  # Finds a token
8
- def find(token, params = {})
8
+ def find(token, params = {webhooks: true})
9
9
  client.find(:token, token, params)
10
10
  end
11
11
  end
@@ -16,6 +16,7 @@ module Trello
16
16
  attributes[:member_id] = fields['idMember']
17
17
  attributes[:created_at] = Time.iso8601(fields['dateCreated'])
18
18
  attributes[:permissions] = fields['permissions'] || {}
19
+ attributes[:webhooks] = fields['webhooks']
19
20
  end
20
21
 
21
22
  # Returns a reference to the user who authorized the token.
@@ -0,0 +1,63 @@
1
+ module Trello
2
+ # A webhook is an url called each time a specified idModel is updated
3
+ class Webhook < BasicData
4
+ register_attributes :id, :description, :id_model, :callback_url, :active,
5
+ :readonly => [ :id ]
6
+ validates_presence_of :id, :id_model, :callback_url
7
+ validates_length_of :description, :in => 1..16384
8
+
9
+ class << self
10
+ # Find a specific webhook by its id.
11
+ def find(id, params = {})
12
+ client.find(:webhook, id, params)
13
+ end
14
+
15
+ # Create a new webhook and save it on Trello.
16
+ def create(options)
17
+ client.create(:webhook,
18
+ 'description' => options[:description],
19
+ 'idModel' => options[:id_model],
20
+ 'callbackURL' => options[:callback_url])
21
+ end
22
+ end
23
+
24
+ def update_fields(fields)
25
+ attributes[:id] = fields['id']
26
+ attributes[:description] = fields['description']
27
+ attributes[:id_model] = fields['idModel']
28
+ attributes[:callback_url] = fields['callbackURL']
29
+ attributes[:active] = fields['active']
30
+ self
31
+ end
32
+
33
+ def save
34
+ # If we have an id, just update our fields.
35
+ return update! if id
36
+
37
+ client.post("/webhooks", {
38
+ :description => description,
39
+ :idModel => id_model,
40
+ :callbackURL => callback_url
41
+ }).json_into(self)
42
+ end
43
+
44
+ def update!
45
+ client.put("/webhooks/#{id}", {
46
+ :description => description,
47
+ :idModel => id_model,
48
+ :callbackURL => callback_url,
49
+ :active => active
50
+ })
51
+ end
52
+
53
+ # Delete this webhook
54
+ def delete
55
+ client.delete("/webhooks/#{id}")
56
+ end
57
+
58
+ # Check if the webhook is activated
59
+ def activated?
60
+ active
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module Trello
4
+ describe Association do
5
+ include Helpers
6
+
7
+ let(:organization) { client.find(:organization, "4ee7e59ae582acdec8000291") }
8
+ let(:client) { Client.new(:consumer_key => "xxx") }
9
+
10
+ before(:each) do
11
+ client.stub(:get).with("/organizations/4ee7e59ae582acdec8000291", {}).
12
+ and_return organization_payload
13
+ client.stub(:get).with("/organizations/4ee7e59ae582acdec8000291/boards/all").
14
+ and_return boards_payload
15
+ end
16
+
17
+ it "should set the proper client for all associated boards of the organization" do
18
+ organization.boards.first.client.consumer_key.should == "xxx"
19
+ end
20
+
21
+ end
22
+ end
data/spec/spec_helper.rb CHANGED
@@ -295,4 +295,24 @@ module Helpers
295
295
  def label_name_payload
296
296
  JSON.generate(label_name_details)
297
297
  end
298
+
299
+ def webhooks_details
300
+ [
301
+ {
302
+ "id" => "webhookid",
303
+ "description" => "Test webhook",
304
+ "idModel" => "1234",
305
+ "callbackURL" => "http://example.org/webhook",
306
+ "active" => true
307
+ }
308
+ ]
309
+ end
310
+
311
+ def webhooks_payload
312
+ JSON.generate(webhooks_details)
313
+ end
314
+
315
+ def webhook_payload
316
+ JSON.generate(webhooks_details.first)
317
+ end
298
318
  end
data/spec/token_spec.rb CHANGED
@@ -15,12 +15,12 @@ module Trello
15
15
  let(:client) { Trello.client }
16
16
 
17
17
  it "delegates to Trello.client#find" do
18
- client.should_receive(:find).with(:token, '1234', {})
18
+ client.should_receive(:find).with(:token, '1234', {:webhooks => true})
19
19
  Token.find('1234')
20
20
  end
21
21
 
22
22
  it "is equivalent to client#find" do
23
- Token.find('1234').should eq(token)
23
+ Token.find('1234', {}).should eq(token)
24
24
  end
25
25
  end
26
26
 
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ module Trello
4
+ describe Webhook do
5
+ include Helpers
6
+
7
+ let(:webhook) { client.find(:webhook, "1234") }
8
+ let(:client) { Client.new }
9
+
10
+ before(:each) do
11
+ client.stub(:get).with("/webhooks/1234", {}).and_return webhook_payload
12
+ end
13
+
14
+ context "finding" do
15
+ let(:client) { Trello.client }
16
+
17
+ it "delegates to Trello.client#find" do
18
+ client.should_receive(:find).with(:webhook, '1234', {})
19
+ Webhook.find('1234')
20
+ end
21
+
22
+ it "is equivalent to client#find" do
23
+ Webhook.find('1234').should eq(webhook)
24
+ end
25
+ end
26
+
27
+ context "creating" do
28
+ let(:client) { Trello.client }
29
+
30
+ it "creates a new webhook" do
31
+ webhook = Webhook.new(webhooks_details.first)
32
+ webhook.should be_valid
33
+ end
34
+
35
+ it 'creates a new webhook and saves it on Trello', :refactor => true do
36
+ payload = {
37
+ :name => 'Test Card',
38
+ :desc => nil,
39
+ }
40
+
41
+ webhook = webhooks_details.first
42
+ result = JSON.generate(webhook)
43
+
44
+ expected_payload = {:description => webhook[:description], :idModel => webhook[:idModel], :callbackURL => webhook[:callbackURL]}
45
+
46
+ client.should_receive(:post).with("/webhooks", expected_payload).and_return result
47
+
48
+ webhook = Webhook.create(webhooks_details.first)
49
+
50
+ webhook.class.should be Webhook
51
+ end
52
+ end
53
+
54
+ context "updating" do
55
+ it "updating description does a put on the correct resource with the correct value" do
56
+ expected_new_description = "xxx"
57
+
58
+ expected_payload = {:description => expected_new_description, :idModel => webhook.id_model, :callbackURL => webhook.callback_url, :active => webhook.active}
59
+
60
+ client.should_receive(:put).once.with("/webhooks/#{webhook.id}", expected_payload)
61
+
62
+ webhook.description = expected_new_description
63
+ webhook.save
64
+ end
65
+ end
66
+
67
+ context "deleting" do
68
+ it "deletes the webhook" do
69
+ client.should_receive(:delete).with("/webhooks/#{webhook.id}")
70
+ webhook.delete
71
+ end
72
+ end
73
+
74
+ context "activated?" do
75
+ it "returns the active attribute" do
76
+ webhook.activated?.should be_true
77
+ end
78
+ end
79
+ end
80
+ end
metadata CHANGED
@@ -1,32 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-trello
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Jeremy Tregunna
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-09-02 00:00:00.000000000 Z
12
+ date: 2013-09-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activemodel
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: addressable
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,20 +46,23 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: json
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: oauth
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :runtime
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rest-client
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ~>
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :runtime
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ~>
81
92
  - !ruby/object:Gem::Version
@@ -111,9 +122,11 @@ files:
111
122
  - lib/trello/organization.rb
112
123
  - lib/trello/string.rb
113
124
  - lib/trello/token.rb
125
+ - lib/trello/webhook.rb
114
126
  - lib/trello.rb
115
127
  - README.md
116
128
  - spec/action_spec.rb
129
+ - spec/association_spec.rb
117
130
  - spec/basic_auth_policy_spec.rb
118
131
  - spec/board_spec.rb
119
132
  - spec/card_spec.rb
@@ -134,33 +147,36 @@ files:
134
147
  - spec/string_spec.rb
135
148
  - spec/token_spec.rb
136
149
  - spec/trello_spec.rb
150
+ - spec/webhook_spec.rb
137
151
  homepage: https://github.com/jeremytregunna/ruby-trello
138
152
  licenses:
139
153
  - MIT
140
- metadata: {}
141
154
  post_install_message:
142
155
  rdoc_options:
143
156
  - --charset=UTF-8
144
157
  require_paths:
145
158
  - lib
146
159
  required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
147
161
  requirements:
148
- - - '>='
162
+ - - ! '>='
149
163
  - !ruby/object:Gem::Version
150
164
  version: '0'
151
165
  required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
152
167
  requirements:
153
- - - '>='
168
+ - - ! '>='
154
169
  - !ruby/object:Gem::Version
155
170
  version: 1.3.6
156
171
  requirements: []
157
172
  rubyforge_project: ruby-trello
158
- rubygems_version: 2.0.3
173
+ rubygems_version: 1.8.25
159
174
  signing_key:
160
- specification_version: 4
175
+ specification_version: 3
161
176
  summary: A wrapper around the trello.com API.
162
177
  test_files:
163
178
  - spec/action_spec.rb
179
+ - spec/association_spec.rb
164
180
  - spec/basic_auth_policy_spec.rb
165
181
  - spec/board_spec.rb
166
182
  - spec/card_spec.rb
@@ -181,3 +197,4 @@ test_files:
181
197
  - spec/string_spec.rb
182
198
  - spec/token_spec.rb
183
199
  - spec/trello_spec.rb
200
+ - spec/webhook_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 09926829a9c5e626cd0ab3796ab1a57af77c294a
4
- data.tar.gz: 9694ed068bacd16f153e35384a5f6641378cb6e6
5
- SHA512:
6
- metadata.gz: 5802afb500a67024cc96f203a239c39ef1844102d3278e7398a7c6142edea202fbe74f6965932ac7efd9e3b12dd9906e5ef614218567ec060cf487888753f4b8
7
- data.tar.gz: 7f6208ed5447fa1ae89e4a5d43dab717c8b986e2548c5577407e89b4d5ac5e63b2e8248cecf1606dde8eec2f3a102145dd5c5fa8548e596d19cbd8f6ae244aac