plancast 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,30 @@ Hash.send :include, Hashie::HashExtensions
7
7
 
8
8
  module Plancast
9
9
 
10
+ VERSION = "0.1.0".freeze
11
+
12
+ def self.configure
13
+ yield self
14
+ true
15
+ end
16
+
17
+ def self.api_url(endpoint, version = self.api_version)
18
+ "http://api.plancast.com/#{version}#{endpoint}.json"
19
+ end
20
+
21
+ # class << self
22
+ # attr_accessor :api_key
23
+ # attr_accessor :api_version
24
+ # end
25
+
26
+ def self.api_version
27
+ @api_version || "02"
28
+ end
29
+
30
+ def self.api_version=(value)
31
+ @api_version = value
32
+ end
33
+
10
34
  class PlancastError < StandardError
11
35
  attr_reader :data
12
36
 
@@ -1,7 +1,7 @@
1
1
  module Plancast
2
2
  class Client
3
3
  include HTTParty
4
- base_uri 'api.plancast.com/01'
4
+ base_uri "api.plancast.com/#{Plancast.api_version}"
5
5
  format :json
6
6
 
7
7
  attr_reader :username
@@ -12,62 +12,91 @@ module Plancast
12
12
  end
13
13
 
14
14
  def verify_credentials
15
- Hashie::Mash.new(self.class.get("/account/verify_credentials.json"))
15
+ self.class.get("/account/verify_credentials.json")
16
16
  end
17
17
 
18
- def home_timeline
19
- Hashie::Mash.new(self.class.get("/plans/home_timeline.json"))
18
+ def user(query={})
19
+ self.class.get("/users/show.json", :query => query)
20
20
  end
21
21
 
22
- def user_timeline(username=self.username)
23
- timeline = Hashie::Mash.new(self.class.get("/plans/user_timeline.json"))
22
+ def subscriptions(query={})
23
+ self.class.get("/users/subscriptions.json", :query => query)
24
24
  end
25
25
 
26
- def update(details={})
27
- plan = Hashie::Mash.new(self.class.post("/plans/update.json", :body => details))
26
+ def update_subscription(options={})
27
+ self.class.post("/subscriptions/update.json", :body => options)
28
28
  end
29
29
 
30
- def attend(plan_id)
31
- plan = Hashie::Mash.new(self.class.post("/plans/attend.json", :query => {:plan_id => plan_id}))
30
+ def destroy_subscription(options={})
31
+ self.class.post("/subscriptions/destroy.json", :body => options)
32
32
  end
33
33
 
34
- def unattend(attendance_id)
35
- plan = Hashie::Mash.new(self.class.post("/plans/destroy.json", :query => {:attendance_id => attendance_id}))
34
+ def subscribers(query={})
35
+ self.class.get("/users/subscribers.json", :query => query)
36
36
  end
37
37
 
38
- def plan(attendance_id)
39
- plan = Hashie::Mash.new(self.class.get("/plans/show.json", :query => {:attendance_id => attendance_id}))
38
+ def discover_friends(query={})
39
+ self.class.get("/users/discover_friends.json", :query => query)
40
40
  end
41
41
 
42
- def search_plans(q, options={})
43
- results = Hashie::Mash.new(self.class.get("/plans/search.json", :query => options.merge({:q => q})))
42
+ def search_users(q, options={})
43
+ self.class.get("/users/search.json", :query => options.merge({:q => q}))
44
44
  end
45
45
 
46
- def user(screen_name=nil)
47
- user = Hashie::Mash.new(self.class.get("/users/show.json", :query => {:screen_name => screen_name}))
46
+ def plans(query = {})
47
+ self.class.get("/plans/user.json", :query => query)
48
48
  end
49
49
 
50
- def search_users(q, options={})
51
- results = Hashie::Mash.new(self.class.get("/users/search.json", :query => options.merge({:q => q})))
50
+ def home
51
+ self.class.get("/plans/home.json")
52
+ end
53
+
54
+ def plan(query = {})
55
+ self.class.get("/plans/show.json", :query => query)
52
56
  end
53
57
 
54
- def subscriptions(user_id)
55
- results = self.class.get("/users/subscriptions.json", :query => {:user_id => user_id}).map{|s| Hashie::Mash.new(s)}
58
+ def search_plans(query)
59
+ self.class.get("/plans/search.json", :query => query)
56
60
  end
57
61
 
58
- def subscribers(user_id)
59
- results = self.class.get("/users/subscribers.json", :query => {:user_id => user_id}).map{|s| Hashie::Mash.new(s)}
62
+ def parse_when(q)
63
+ date = self.class.get("/plans/parse_when.json", :query => {:when => q})
64
+ date.start = Time.at(date.start)
65
+ date.stop = Time.at(date.stop)
66
+ date
60
67
  end
61
68
 
62
- def create_comment(details={})
63
- comment = Hashie::Mash.new(self.class.post("/comments/update.json", :body => details))
69
+ def parse_where(where)
70
+ locations = self.class.get("/plans/parse_where.json", :query => {:where => where})
71
+ locations.each{|l| l.latitude = l.latitude.to_f; l.longitude = l.longitude.to_f}
72
+ locations
64
73
  end
65
74
 
66
- def create_friendship(user_id)
67
- user = Hashie::Mash.new(self.class.post("/friendships/create.json", :body => {:user_id => user_id}))
75
+ def update(details={})
76
+ self.class.post("/plans/update.json", :body => details)
77
+ end
78
+
79
+ def attend(details={})
80
+ self.class.post("/plans/attend.json", :body => details)
68
81
  end
69
82
 
83
+ def user_timeline(username=self.username)
84
+ self.class.get("/plans/user_timeline.json")
85
+ end
86
+
87
+ def unattend(options)
88
+ self.class.post("/plans/destroy.json", :body => options)
89
+ end
90
+
91
+ def update_comment(details={})
92
+ self.class.post("/comments/update.json", :body => details)
93
+ end
70
94
 
95
+ def destroy_comment(comment_id)
96
+ self.class.post("/comments/destroy.json", :body => {:comment_id => comment_id})
97
+ end
98
+
99
+
71
100
  def self.get(*args); handle_response super end
72
101
  def self.post(*args); handle_response super end
73
102
 
@@ -80,7 +109,11 @@ module Plancast
80
109
  when 500...600; raise ServerError.new(response.code)
81
110
  else; response
82
111
  end
83
- response
112
+ if response.is_a?(Array)
113
+ response.map{|item| Hashie::Mash.new(item)}
114
+ else
115
+ Hashie::Mash.new(response)
116
+ end
84
117
  end
85
118
 
86
119
  end
@@ -2,11 +2,10 @@ require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
4
 
5
- require 'shoulda'
5
+ require 'redgreen'
6
6
  require 'matchy'
7
7
  require 'fakeweb'
8
8
 
9
-
10
9
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
10
  $LOAD_PATH.unshift(File.dirname(__FILE__))
12
11
  require 'plancast'
@@ -16,6 +15,9 @@ require 'plancast'
16
15
  # You don't usually want your test suite to make HTTP connections, do you?
17
16
  FakeWeb.allow_net_connect = false
18
17
 
18
+ class Test::Unit::TestCase
19
+ end
20
+
19
21
  def fixture_file(filename)
20
22
  return '' if filename == ''
21
23
  file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
@@ -25,7 +27,7 @@ end
25
27
  def plancast_url(url, options={})
26
28
  options[:username] ||= 'pengwynn'
27
29
  options[:password] ||= 'password'
28
- url =~ /^http/ ? url : "http://#{options[:username]}:#{options[:password]}@api.plancast.com/01#{url}"
30
+ url =~ /^http/ ? url : "http://#{options[:username]}:#{options[:password]}@api.plancast.com/#{Plancast.api_version}#{url}"
29
31
  end
30
32
 
31
33
  def stub_request(method, url, filename, status=nil)
@@ -40,5 +42,4 @@ end
40
42
  def stub_get(*args); stub_request(:get, *args) end
41
43
  def stub_post(*args); stub_request(:post, *args) end
42
44
 
43
- class Test::Unit::TestCase
44
- end
45
+
@@ -0,0 +1,159 @@
1
+ require 'helper'
2
+
3
+ class PlancastTest < Test::Unit::TestCase
4
+
5
+ context "Plancast API" do
6
+
7
+ setup do
8
+ @client = Plancast::Client.new('pengwynn', 'password')
9
+ end
10
+
11
+ should "verify credentials" do
12
+
13
+ stub_get("/account/verify_credentials.json", "verify_credentials.json")
14
+ lambda {@client.verify_credentials}.should_not raise_error
15
+ user = @client.verify_credentials
16
+ user.username.should == 'pengwynn'
17
+ user.name.should == 'Wynn Netherland'
18
+
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 "get the details of a user" do
27
+ stub_get("/users/show.json?user_id=1", "user.json")
28
+ user = @client.user(:user_id => 1)
29
+ user.name.should == 'Mark Hendrickson'
30
+ user.twitter_username.should == 'mhendric'
31
+ end
32
+
33
+ should "get a users's subscription" do
34
+ stub_get("/users/subscriptions.json?user_id=30", "subscriptions.json")
35
+ subscriptions = @client.subscriptions(:user_id => 30).users
36
+ subscriptions.size.should == 25
37
+ subscriptions.first.screen_name = 'ifindkarma'
38
+ end
39
+
40
+ should "get a user's subscribers" do
41
+ stub_get("/users/subscribers.json?user_id=1", "subscriptions.json")
42
+ subscribers = @client.subscribers(:user_id => 1).users
43
+ subscribers.size.should == 25
44
+ subscribers.first.screen_name = 'ifindkarma'
45
+ end
46
+
47
+ should "get users who are friends of a particular user on Facebook or Twitter" do
48
+ stub_get("/users/discover_friends.json?service=twitter", "discover_friends.json")
49
+ response = @client.discover_friends(:service => :twitter)
50
+ subscriptions = response.users
51
+ subscriptions.size.should == 25
52
+ subscriptions.first.screen_name = 'graysky'
53
+ response.has_next_page?.should == true
54
+ end
55
+
56
+ should "search for users by keyword" do
57
+ stub_get("/users/search.json?q=mark", "users_search.json")
58
+ response = @client.search_users('mark')
59
+ results = response.results
60
+ results.first.username.should == "mark"
61
+ end
62
+
63
+ should "create or update a subscription" do
64
+ stub_post("/subscriptions/update.json", "update_subscription.json")
65
+ subscription = @client.update_subscription(:user_id => 1)
66
+ subscription.username.should == "peter"
67
+ end
68
+
69
+ should "delete a subscription" do
70
+ stub_post("/subscriptions/destroy.json", "destroy_subscription.json")
71
+ subscription = @client.destroy_subscription(:user_id => 1)
72
+ subscription.username.should == "peter"
73
+ end
74
+
75
+ should "get the plans of a user" do
76
+ stub_get("/plans/user.json?username=mark", "user_plans.json")
77
+ response = @client.plans(:username => 'mark')
78
+ plans = response.plans
79
+ plans.first.attendance_url.should == 'http://plancast.com/a/32st'
80
+ end
81
+
82
+ should "get the home timeline of a user (his plans + his friends' plans)" do
83
+ stub_get("/plans/home.json", "home.json")
84
+ timeline = @client.home
85
+ timeline.plans.size.should == 19
86
+ timeline.plans.first.attendance_id.should == '10o'
87
+ end
88
+
89
+ should "get the details of a plan" do
90
+ stub_get("/plans/show.json?plan_id=enf", "plan.json")
91
+ plan = @client.plan(:plan_id => 'enf')
92
+ plan.plan_id.should == 'enf'
93
+ plan.creator.username.should == 'ethan'
94
+ end
95
+
96
+ should "create or update a plan" do
97
+ stub_post("/plans/update.json", "new_plan.json")
98
+ details = {
99
+ :what => "Test Plancast gem",
100
+ :when => "tomorrow"
101
+ }
102
+ plan = @client.update(details)
103
+ plan.attendance_id.should == '3ag4'
104
+ end
105
+
106
+ should "add an attendance to a plan for a user" do
107
+ stub_post("/plans/attend.json", "attend.json")
108
+ info = {
109
+ :attendance_id => 'dho',
110
+ :syndicate_twitter => false
111
+ }
112
+ attendance = @client.attend(info)
113
+ attendance.attendance_id.should == '3ag6'
114
+ end
115
+
116
+ should "delete or unattend a plan" do
117
+ stub_post("/plans/destroy.json", "plan.json")
118
+ attendance = @client.unattend(:plan_id => 'enf')
119
+ attendance.creator.username.should == 'ethan'
120
+ end
121
+
122
+ should "search plans by keyword" do
123
+ stub_get("/plans/search.json?q=party", "plans_search.json")
124
+ plans = @client.search_plans(:q => 'party').plans
125
+ plans.first.plan_id.should == "5bz"
126
+ end
127
+
128
+ should "parse datetime from a string" do
129
+ stub_get("/plans/parse_when.json?when=next%20friday", "parse_when.json")
130
+ date = @client.parse_when("next friday")
131
+ date.start.year.should == 2010
132
+ date.start.month.should == 5
133
+ date.stop.day.should == 28
134
+ end
135
+
136
+ should "parse location from string" do
137
+ stub_get("/plans/parse_where.json?where=london", "parse_where.json")
138
+ locations = @client.parse_where("london")
139
+ locations.first.latitude.should == 51.500152
140
+ locations.first.longitude.should == -0.126236
141
+ end
142
+
143
+ should "create a comment" do
144
+ stub_post("/comments/update.json", "comment.json")
145
+ comment = @client.update_comment(:content => "hello world")
146
+ comment.content.should == 'hello world'
147
+ end
148
+
149
+ should "delete a comment" do
150
+ stub_post("/comments/destroy.json", "comment.json")
151
+ comment = @client.destroy_comment(7513)
152
+ comment.content.should == 'hello world'
153
+ end
154
+
155
+ end
156
+
157
+
158
+
159
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plancast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Wynn Netherland
@@ -9,134 +14,148 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-21 00:00:00 -05:00
17
+ date: 2010-05-22 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
- name: hashie
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
20
22
  requirements:
21
23
  - - ">="
22
24
  - !ruby/object:Gem::Version
25
+ segments:
26
+ - 0
27
+ - 1
28
+ - 3
23
29
  version: 0.1.3
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: httparty
30
+ name: hashie
31
+ prerelease: false
32
+ requirement: *id001
27
33
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: 0.5.0
34
- version:
39
+ segments:
40
+ - 0
41
+ - 1
42
+ - 0
43
+ version: 0.1.0
44
+ name: monster_mash
45
+ prerelease: false
46
+ requirement: *id002
47
+ type: :runtime
35
48
  - !ruby/object:Gem::Dependency
36
- name: shoulda
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ - 7
56
+ - 6
57
+ version: 0.7.6
58
+ name: yajl-ruby
59
+ prerelease: false
60
+ requirement: *id003
61
+ type: :runtime
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
40
64
  requirements:
41
65
  - - ">="
42
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 2
69
+ - 10
70
+ - 1
43
71
  version: 2.10.1
44
- version:
45
- - !ruby/object:Gem::Dependency
46
- name: matchy
72
+ name: shoulda
73
+ prerelease: false
74
+ requirement: *id004
47
75
  type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
76
+ - !ruby/object:Gem::Dependency
77
+ version_requirements: &id005 !ruby/object:Gem::Requirement
50
78
  requirements:
51
79
  - - "="
52
80
  - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ - 4
84
+ - 0
53
85
  version: 0.4.0
54
- version:
55
- - !ruby/object:Gem::Dependency
56
- name: fakeweb
86
+ name: matchy
87
+ prerelease: false
88
+ requirement: *id005
57
89
  type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
90
+ - !ruby/object:Gem::Dependency
91
+ version_requirements: &id006 !ruby/object:Gem::Requirement
60
92
  requirements:
61
93
  - - ">="
62
94
  - !ruby/object:Gem::Version
95
+ segments:
96
+ - 1
97
+ - 2
98
+ - 5
63
99
  version: 1.2.5
64
- version:
65
- - !ruby/object:Gem::Dependency
66
- name: yard
100
+ name: fakeweb
101
+ prerelease: false
102
+ requirement: *id006
67
103
  type: :development
68
- version_requirement:
69
- version_requirements: !ruby/object:Gem::Requirement
104
+ - !ruby/object:Gem::Dependency
105
+ version_requirements: &id007 !ruby/object:Gem::Requirement
70
106
  requirements:
71
107
  - - ">="
72
108
  - !ruby/object:Gem::Version
109
+ segments:
110
+ - 0
73
111
  version: "0"
74
- version:
75
- description: Wrapper for the unpublished Plancast API
112
+ name: yard
113
+ prerelease: false
114
+ requirement: *id007
115
+ type: :development
116
+ description: Wrapper for the Plancast API
76
117
  email: wynn.netherland@gmail.com
77
118
  executables: []
78
119
 
79
120
  extensions: []
80
121
 
81
- extra_rdoc_files:
82
- - LICENSE
83
- - README.rdoc
122
+ extra_rdoc_files: []
123
+
84
124
  files:
85
- - .document
86
- - .gitignore
87
- - LICENSE
88
- - README.rdoc
89
- - Rakefile
90
- - VERSION
91
- - lib/plancast.rb
92
125
  - 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
126
+ - lib/plancast.rb
112
127
  has_rdoc: true
113
128
  homepage: http://github.com/pengwynn/plancast
114
129
  licenses: []
115
130
 
116
131
  post_install_message:
117
- rdoc_options:
118
- - --charset=UTF-8
132
+ rdoc_options: []
133
+
119
134
  require_paths:
120
135
  - lib
121
136
  required_ruby_version: !ruby/object:Gem::Requirement
122
137
  requirements:
123
138
  - - ">="
124
139
  - !ruby/object:Gem::Version
140
+ segments:
141
+ - 0
125
142
  version: "0"
126
- version:
127
143
  required_rubygems_version: !ruby/object:Gem::Requirement
128
144
  requirements:
129
145
  - - ">="
130
146
  - !ruby/object:Gem::Version
131
- version: "0"
132
- version:
147
+ segments:
148
+ - 1
149
+ - 3
150
+ - 6
151
+ version: 1.3.6
133
152
  requirements: []
134
153
 
135
154
  rubyforge_project:
136
- rubygems_version: 1.3.5
155
+ rubygems_version: 1.3.6
137
156
  signing_key:
138
157
  specification_version: 3
139
- summary: Wrapper for the unpublished Plancast API
158
+ summary: Wrapper for the Plancast API
140
159
  test_files:
141
160
  - test/helper.rb
142
- - test/test_plancast.rb
161
+ - test/plancast_test.rb