plancast 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ require 'shoulda'
6
+ require 'matchy'
7
+ require 'fakeweb'
8
+
9
+
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
12
+ require 'plancast'
13
+
14
+
15
+ # Set the default allow_net_connect option--usually you'll want this off.
16
+ # You don't usually want your test suite to make HTTP connections, do you?
17
+ FakeWeb.allow_net_connect = false
18
+
19
+ def fixture_file(filename)
20
+ return '' if filename == ''
21
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
22
+ File.read(file_path)
23
+ end
24
+
25
+ def plancast_url(url, options={})
26
+ options[:username] ||= 'pengwynn'
27
+ options[:password] ||= 'password'
28
+ url =~ /^http/ ? url : "http://#{options[:username]}:#{options[:password]}@api.plancast.com/01#{url}"
29
+ end
30
+
31
+ def stub_request(method, url, filename, status=nil)
32
+ options = {:body => ""}
33
+ options.merge!({:body => fixture_file(filename)}) if filename
34
+ options.merge!({:body => status.last}) if status
35
+ options.merge!({:status => status}) if status
36
+
37
+ FakeWeb.register_uri(method, plancast_url(url), options)
38
+ end
39
+
40
+ def stub_get(*args); stub_request(:get, *args) end
41
+ def stub_post(*args); stub_request(:post, *args) end
42
+
43
+ class Test::Unit::TestCase
44
+ end
@@ -0,0 +1,128 @@
1
+ require 'helper'
2
+
3
+ class TestPlancast < Test::Unit::TestCase
4
+ context "When using the UNDOCUMENTED Plancast API" do
5
+ setup do
6
+ @client = Plancast::Client.new('pengwynn', 'password')
7
+ end
8
+
9
+ should "verify credentials" do
10
+ stub_get("/account/verify_credentials.json", "verify_credentials.json")
11
+ lambda {@client.verify_credentials}.should_not raise_error
12
+ end
13
+
14
+ should "return user info when verifying credentials" do
15
+ stub_get("/account/verify_credentials.json", "verify_credentials.json")
16
+ user = @client.verify_credentials
17
+ user.screen_name.should == 'pengwynn'
18
+ user.user.status.attendees.first.screen_name.should == 'damon'
19
+ end
20
+
21
+ should "raise error on invalid credentials" do
22
+ stub_get("/account/verify_credentials.json", "", ['401'])
23
+ lambda {@client.verify_credentials}.should raise_error(Plancast::Unauthorized)
24
+ end
25
+
26
+ should "return the home timeline" do
27
+ stub_get("/plans/home_timeline.json", "home_timeline.json")
28
+ timeline = @client.home_timeline
29
+ timeline.plans.size.should == 25
30
+ timeline.plans.first.plan_id.should == 'c9f'
31
+ timeline.plans.first.user.screen_name.should == 'davemcclure'
32
+ end
33
+
34
+ should "return the user timeline for the authenticated user" do
35
+ stub_get("/plans/user_timeline.json", "user_timeline.json")
36
+ timeline = @client.user_timeline
37
+ timeline.plans.first.what.should == 'Create a Plancast wrapper when the API drops'
38
+ #timeline.plans.first.start.should == Time.at(1269302400)
39
+ end
40
+
41
+ should "create a plan" do
42
+ stub_post("/plans/update.json", "update.json")
43
+ details = {
44
+ :what => "OpenBeta4",
45
+ :when => "Thursday",
46
+ :where => "723 n hudson, 73120",
47
+ :syndicate_twitter => 1
48
+ }
49
+ plan = @client.update(details)
50
+ plan.plan_id.should == 'utn'
51
+ plan.is_attending?.should == true
52
+ end
53
+
54
+ should "attend a plan" do
55
+ stub_post("/plans/attend.json?plan_id=u6i", "attend.json")
56
+ plan = @client.attend('u6i')
57
+ plan.attendance_id.should == '23rk'
58
+ plan.what.should == 'Android Developer Day'
59
+ end
60
+
61
+ should "unattend a plan" do
62
+ stub_post("/plans/destroy.json?attendance_id=23rl", "unattend.json")
63
+ plan = @client.unattend('23rl')
64
+ plan.attendance_id.should == '23rl'
65
+ plan.plan_id.should == '2n7'
66
+ end
67
+
68
+ should "show plan details" do
69
+ stub_get("/plans/show.json?attendance_id=mkg", "plan.json")
70
+ plan = @client.plan('mkg')
71
+ plan.attendance_id.should == 'mkg'
72
+ plan.plan_id.should == 'c9f'
73
+ end
74
+
75
+ should "search for plans" do
76
+ stub_get("/plans/search.json?q=bradleyjoyce", "search.json")
77
+ results = @client.search_plans('bradleyjoyce').results
78
+ results.first.plan_id.should == "1"
79
+ results.first.what.should == 'Drinks'
80
+ end
81
+
82
+ should "show user details" do
83
+ stub_get("/users/show.json?screen_name=mark", "user.json")
84
+ user = @client.user('mark')
85
+ user.name.should == 'Mark Hendrickson'
86
+ user.has_twitter?.should == true
87
+ end
88
+
89
+ should"search for users" do
90
+ stub_get("/users/search.json?q=bradleyjoyce", "user_search.json")
91
+ results = @client.search_users('bradleyjoyce').results
92
+ results.first.screen_name.should == "bradleyjoyce"
93
+ end
94
+
95
+ should "create a friendship" do
96
+ stub_post("/friendships/create.json", "create_friendship.json")
97
+ user = @client.create_friendship(35)
98
+ user.screen_name.should == "defunkt"
99
+ end
100
+
101
+ should "list subscriptions" do
102
+ stub_get("/users/subscriptions.json?user_id=30", "subscriptions.json")
103
+ subscriptions = @client.subscriptions(30)
104
+ subscriptions.size.should == 25
105
+ subscriptions.first.screen_name = 'soph'
106
+ end
107
+
108
+ should "list subscribers" do
109
+ stub_get("/users/subscribers.json?user_id=30", "subscribers.json")
110
+ subscribers = @client.subscribers(30)
111
+ subscribers.size.should == 25
112
+ subscribers.first.screen_name = 'mark'
113
+ end
114
+
115
+ should "create comments" do
116
+ stub_post("/comments/update.json", "comment.json")
117
+ info = {
118
+ :plan_id => 1,
119
+ :text => "This is a comment"
120
+ }
121
+ comment = @client.create_comment(info)
122
+ comment.text.should == 'This is a comment'
123
+ comment.user.screen_name.should == 'pengwynn'
124
+ end
125
+
126
+ end
127
+
128
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plancast
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Wynn Netherland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-21 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hashie
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: shoulda
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.10.1
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: matchy
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.4.0
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakeweb
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.2.5
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: yard
67
+ type: :development
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ description: Wrapper for the unpublished Plancast API
76
+ email: wynn.netherland@gmail.com
77
+ executables: []
78
+
79
+ extensions: []
80
+
81
+ extra_rdoc_files:
82
+ - LICENSE
83
+ - README.rdoc
84
+ files:
85
+ - .document
86
+ - .gitignore
87
+ - LICENSE
88
+ - README.rdoc
89
+ - Rakefile
90
+ - VERSION
91
+ - lib/plancast.rb
92
+ - lib/plancast/client.rb
93
+ - plancast.gemspec
94
+ - test/fixtures/attend.json
95
+ - test/fixtures/comment.json
96
+ - test/fixtures/create_friendship.json
97
+ - test/fixtures/featured.json
98
+ - test/fixtures/home_timeline.json
99
+ - test/fixtures/parse_when.json
100
+ - test/fixtures/plan.json
101
+ - test/fixtures/search.json
102
+ - test/fixtures/subscribers.json
103
+ - test/fixtures/subscriptions.json
104
+ - test/fixtures/unattend.json
105
+ - test/fixtures/update.json
106
+ - test/fixtures/user.json
107
+ - test/fixtures/user_search.json
108
+ - test/fixtures/user_timeline.json
109
+ - test/fixtures/verify_credentials.json
110
+ - test/helper.rb
111
+ - test/test_plancast.rb
112
+ has_rdoc: true
113
+ homepage: http://github.com/pengwynn/plancast
114
+ licenses: []
115
+
116
+ post_install_message:
117
+ rdoc_options:
118
+ - --charset=UTF-8
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: "0"
126
+ version:
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: "0"
132
+ version:
133
+ requirements: []
134
+
135
+ rubyforge_project:
136
+ rubygems_version: 1.3.5
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Wrapper for the unpublished Plancast API
140
+ test_files:
141
+ - test/helper.rb
142
+ - test/test_plancast.rb