ticketmaster-basecamp 0.2.5 → 0.2.6
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.
- data/VERSION +1 -1
- data/lib/basecamp/basecamp.rb +87 -84
- data/lib/provider/basecamp.rb +7 -2
- data/spec/fixtures/project_count.xml +5 -0
- data/spec/ticketmaster-basecamp_spec.rb +4 -0
- data/ticketmaster-basecamp.gemspec +3 -2
- metadata +6 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/lib/basecamp/basecamp.rb
CHANGED
@@ -195,6 +195,9 @@ class BasecampAPI
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
+
class Account < Resource
|
199
|
+
end
|
200
|
+
|
198
201
|
class Project < Resource
|
199
202
|
end
|
200
203
|
|
@@ -292,11 +295,11 @@ class BasecampAPI
|
|
292
295
|
# are returned. If complete is false, only uncompleted lists are returned.
|
293
296
|
def self.all(project_id, complete = nil)
|
294
297
|
filter = case complete
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
298
|
+
when nil then "all"
|
299
|
+
when true then "finished"
|
300
|
+
when false then "pending"
|
301
|
+
else raise ArgumentError, "invalid value for `complete'"
|
302
|
+
end
|
300
303
|
|
301
304
|
find(:all, :params => { :project_id => project_id, :filter => filter })
|
302
305
|
end
|
@@ -396,10 +399,10 @@ class BasecampAPI
|
|
396
399
|
case @hash[name]
|
397
400
|
when Hash then
|
398
401
|
@hash[name] = if (@hash[name].keys.length == 1 && @hash[name].values.first.is_a?(Array))
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
402
|
+
@hash[name].values.first.map { |v| Record.new(@hash[name].keys.first, v) }
|
403
|
+
else
|
404
|
+
Record.new(name, @hash[name])
|
405
|
+
end
|
403
406
|
else
|
404
407
|
@hash[name]
|
405
408
|
end
|
@@ -435,9 +438,9 @@ class BasecampAPI
|
|
435
438
|
|
436
439
|
private
|
437
440
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
+
def dashify(name)
|
442
|
+
name.to_s.tr("_", "-")
|
443
|
+
end
|
441
444
|
end
|
442
445
|
|
443
446
|
attr_accessor :use_xml
|
@@ -511,7 +514,7 @@ class BasecampAPI
|
|
511
514
|
# Updates an existing milestone.
|
512
515
|
def update_milestone(id, data, move = false, move_off_weekends = false)
|
513
516
|
record "/milestones/update/#{id}", :milestone => data,
|
514
|
-
|
517
|
+
:move_upcoming_milestones => move,
|
515
518
|
:move_upcoming_milestones_off_weekends => move_off_weekends
|
516
519
|
end
|
517
520
|
|
@@ -532,96 +535,96 @@ class BasecampAPI
|
|
532
535
|
|
533
536
|
private
|
534
537
|
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
538
|
+
# Make a raw web-service request to Basecamp. This will return a Hash of
|
539
|
+
# Arrays of the response, and may seem a little odd to the uninitiated.
|
540
|
+
def request(path, parameters = {})
|
541
|
+
response = Basecamp.connection.post(path, convert_body(parameters), "Content-Type" => content_type)
|
539
542
|
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
end
|
543
|
+
if response.code.to_i / 100 == 2
|
544
|
+
result = XmlSimple.xml_in(response.body, 'keeproot' => true, 'contentkey' => '__content__', 'forcecontent' => true)
|
545
|
+
typecast_value(result)
|
546
|
+
else
|
547
|
+
raise "#{response.message} (#{response.code})"
|
546
548
|
end
|
549
|
+
end
|
547
550
|
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
551
|
+
# A convenience method for wrapping the result of a query in a Record
|
552
|
+
# object. This assumes that the result is a singleton, not a collection.
|
553
|
+
def record(path, parameters={})
|
554
|
+
result = request(path, parameters)
|
555
|
+
(result && !result.empty?) ? Record.new(result.keys.first, result.values.first) : nil
|
556
|
+
end
|
554
557
|
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
558
|
+
# A convenience method for wrapping the result of a query in Record
|
559
|
+
# objects. This assumes that the result is a collection--any singleton
|
560
|
+
# result will be wrapped in an array.
|
561
|
+
def records(node, path, parameters={})
|
562
|
+
result = request(path, parameters).values.first or return []
|
563
|
+
result = result[node] or return []
|
564
|
+
result = [result] unless Array === result
|
565
|
+
result.map { |row| Record.new(node, row) }
|
566
|
+
end
|
564
567
|
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
+
def convert_body(body)
|
569
|
+
body = use_xml ? body.to_legacy_xml : body.to_yaml
|
570
|
+
end
|
568
571
|
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
+
def content_type
|
573
|
+
use_xml ? "application/xml" : "application/x-yaml"
|
574
|
+
end
|
572
575
|
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
576
|
+
def typecast_value(value)
|
577
|
+
case value
|
578
|
+
when Hash
|
579
|
+
if value.has_key?("__content__")
|
580
|
+
content = translate_entities(value["__content__"]).strip
|
581
|
+
case value["type"]
|
582
|
+
when "integer" then content.to_i
|
583
|
+
when "boolean" then content == "true"
|
584
|
+
when "datetime" then Time.parse(content)
|
585
|
+
when "date" then Date.parse(content)
|
586
|
+
else content
|
587
|
+
end
|
585
588
|
# a special case to work-around a bug in XmlSimple. When you have an empty
|
586
589
|
# tag that has an attribute, XmlSimple will not add the __content__ key
|
587
590
|
# to the returned hash. Thus, we check for the presense of the 'type'
|
588
591
|
# attribute to look for empty, typed tags, and simply return nil for
|
589
592
|
# their value.
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
593
|
+
elsif value.keys == %w(type)
|
594
|
+
nil
|
595
|
+
elsif value["nil"] == "true"
|
596
|
+
nil
|
594
597
|
# another special case, introduced by the latest rails, where an array
|
595
598
|
# type now exists. This is parsed by XmlSimple as a two-key hash, where
|
596
599
|
# one key is 'type' and the other is the actual array value.
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
else
|
601
|
-
value.empty? ? nil : value.inject({}) do |h,(k,v)|
|
602
|
-
h[k] = typecast_value(v)
|
603
|
-
h
|
604
|
-
end
|
605
|
-
end
|
606
|
-
when Array
|
607
|
-
value.map! { |i| typecast_value(i) }
|
608
|
-
case value.length
|
609
|
-
when 0 then nil
|
610
|
-
when 1 then value.first
|
611
|
-
else value
|
612
|
-
end
|
600
|
+
elsif value.keys.length == 2 && value["type"] == "array"
|
601
|
+
value.delete("type")
|
602
|
+
typecast_value(value)
|
613
603
|
else
|
614
|
-
|
604
|
+
value.empty? ? nil : value.inject({}) do |h,(k,v)|
|
605
|
+
h[k] = typecast_value(v)
|
606
|
+
h
|
607
|
+
end
|
608
|
+
end
|
609
|
+
when Array
|
610
|
+
value.map! { |i| typecast_value(i) }
|
611
|
+
case value.length
|
612
|
+
when 0 then nil
|
613
|
+
when 1 then value.first
|
614
|
+
else value
|
615
615
|
end
|
616
|
+
else
|
617
|
+
raise "can't typecast #{value.inspect}"
|
616
618
|
end
|
619
|
+
end
|
617
620
|
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
621
|
+
def translate_entities(value)
|
622
|
+
value.gsub(/</, "<").
|
623
|
+
gsub(/>/, ">").
|
624
|
+
gsub(/"/, '"').
|
625
|
+
gsub(/'/, "'").
|
626
|
+
gsub(/&/, "&")
|
627
|
+
end
|
625
628
|
end
|
626
629
|
|
627
630
|
# A minor hack to let Xml-Simple serialize symbolic keys in hashes
|
data/lib/provider/basecamp.rb
CHANGED
@@ -26,9 +26,14 @@ module TicketMaster::Provider
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def valid?
|
29
|
-
|
29
|
+
begin
|
30
|
+
project_count = BasecampAPI::Project.find(:count)
|
31
|
+
project_count.active >= 0 || project_count.archived >= 0 || project_count.on_hold >= 0
|
32
|
+
rescue
|
33
|
+
false
|
34
|
+
end
|
30
35
|
end
|
31
|
-
|
36
|
+
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
@@ -2,6 +2,10 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe "TicketmasterBasecamp" do
|
4
4
|
before(:each) do
|
5
|
+
headers = {'Authorization' => 'Basic MDAwMDAwOkJhc2VjYW1w'}
|
6
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
7
|
+
mock.get '/projects/count.xml', headers, fixture_for('project_count'), 200
|
8
|
+
end
|
5
9
|
@ticketmaster = TicketMaster.new(:basecamp, {:domain => 'ticketmaster.basecamphq.com', :token => '000000'})
|
6
10
|
end
|
7
11
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ticketmaster-basecamp}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["HybridGroup"]
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"spec/fixtures/comments.xml",
|
33
33
|
"spec/fixtures/comments/74197051.xml",
|
34
34
|
"spec/fixtures/comments/74197096.xml",
|
35
|
+
"spec/fixtures/project_count.xml",
|
35
36
|
"spec/fixtures/projects.xml",
|
36
37
|
"spec/fixtures/projects/5220065.xml",
|
37
38
|
"spec/fixtures/projects/create.xml",
|
@@ -47,7 +48,7 @@ Gem::Specification.new do |s|
|
|
47
48
|
]
|
48
49
|
s.homepage = %q{http://github.com/kiafaldorius/ticketmaster-basecamp}
|
49
50
|
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version = %q{1.6.
|
51
|
+
s.rubygems_version = %q{1.6.1}
|
51
52
|
s.summary = %q{The basecamp provider for ticketmaster}
|
52
53
|
|
53
54
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ticketmaster-basecamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- HybridGroup
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-02 00:00:00
|
18
|
+
date: 2011-06-02 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- spec/fixtures/comments.xml
|
76
76
|
- spec/fixtures/comments/74197051.xml
|
77
77
|
- spec/fixtures/comments/74197096.xml
|
78
|
+
- spec/fixtures/project_count.xml
|
78
79
|
- spec/fixtures/projects.xml
|
79
80
|
- spec/fixtures/projects/5220065.xml
|
80
81
|
- spec/fixtures/projects/create.xml
|
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
118
|
requirements: []
|
118
119
|
|
119
120
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.6.
|
121
|
+
rubygems_version: 1.6.1
|
121
122
|
signing_key:
|
122
123
|
specification_version: 3
|
123
124
|
summary: The basecamp provider for ticketmaster
|