awesm 0.1.5 → 0.1.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/README.md CHANGED
@@ -22,14 +22,19 @@ And in your code:
22
22
  project = Awesm::Project.create(:name => 'TotallyAwesm')
23
23
  project.api_key # => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9'
24
24
 
25
+ # List projects
26
+ projects = Awesm::Project.list
27
+ projects.first.class # => Awesm::Project
28
+
25
29
  # Create a sharing link
26
- # (This is currently very rudimentary--only the options shown will work.)
27
30
  Awesm::Url.share(:url => 'http://developers.awe.sm/',
28
- :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9',
29
- :tool => 'mKU7uN',
30
- :channel => 'twitter',
31
- :destination => 'http://twitter.com/intent/tweet?text=This+is+the+coolest+API+evar!%26url=AWESM_URL%26via=awesm')
32
- # => "http://api.awe.sm/url/share?v=3&url=http://developers.awe.sm/&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&tool=mKU7uN&channel=twitter&destination=http://twitter.com/intent/tweet?text=This+is+the+coolest+API+evar!%26url=AWESM_URL%26via=awesm"
31
+ :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9',
32
+ :tool => 'mKU7uN',
33
+ :channel => 'twitter',
34
+ :destination => 'http://twitter.com/intent/tweet?text=This+is+the+coolest+API+evar!%26url=AWESM_URL%26via=awesm',
35
+ :parent => 'awe.sm_s5d99',
36
+ :user_id => '42')
37
+ # => "http://api.awe.sm/url/share?v=3&url=http://developers.awe.sm/&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&tool=mKU7uN&channel=twitter&destination=http://twitter.com/intent/tweet?text=This+is+the+coolest+API+evar!%26url=AWESM_URL%26via=awesm&parent=awe.sm_s5d99&user_id=42"
33
38
 
34
39
  ## Contributing ##
35
40
 
@@ -41,10 +46,11 @@ And in your code:
41
46
  * push to a topic branch
42
47
  * send us a pull request :)
43
48
 
44
- ## Manitainers ##
49
+ ## Contributors ##
45
50
 
46
51
  * *Sathya Sekaran*
47
52
  * *Michael Durnhofer*
53
+ * *Cody Johnston*
48
54
 
49
55
  ## Many Thanks To ##
50
56
  * our employer, Topspin Media, Inc. (http://topspinmedia.com)
@@ -11,5 +11,18 @@ module Awesm
11
11
  new(response['response']['project'])
12
12
  end
13
13
  end
14
+
15
+ def self.list
16
+ response = post('/list', :query => { :application_key => Awesm.application_key, :subscription_key => Awesm.subscription_key})
17
+ if response.has_key?("error")
18
+ nil
19
+ else
20
+ projects = []
21
+ response['response']['projects'].each do |project|
22
+ projects << new(project)
23
+ end
24
+ projects
25
+ end
26
+ end
14
27
  end
15
28
  end
@@ -1,13 +1,20 @@
1
1
  module Awesm
2
2
  class Url
3
- def self.share(params)
3
+ REQUIRED_SHARE_PARAMS = [:url, :key, :tool, :channel, :destination].freeze
4
+
5
+ def self.share(params = {})
4
6
  if required_params_present_for_share?(params)
5
- "http://api.awe.sm/url/share?v=3&url=#{params[:url]}&key=#{params[:key]}&tool=#{params[:tool]}&channel=#{params[:channel]}&destination=#{params[:destination]}"
7
+ options = params.clone
8
+ options = options.delete_if{|key,value| REQUIRED_SHARE_PARAMS.include?(key) }
9
+ query = options.map{|k,v| "#{k}=#{v}"}.join('&')
10
+ share_url = "http://api.awe.sm/url/share?v=3&url=#{params[:url]}&key=#{params[:key]}&tool=#{params[:tool]}&channel=#{params[:channel]}&destination=#{params[:destination]}"
11
+ share_url += "&#{query}" if query.length > 0
12
+ share_url
6
13
  end
7
14
  end
8
15
 
9
16
  def self.required_params_present_for_share?(params)
10
- [:url, :key, :tool, :channel, :destination].all? do |param|
17
+ REQUIRED_SHARE_PARAMS.all? do |param|
11
18
  params.include?(param)
12
19
  end
13
20
  end
@@ -1,3 +1,3 @@
1
1
  module Awesm
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -1,61 +1,66 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Awesm::Project do
4
- let(:json_response) do
5
- {
6
- "request" => {
7
- "application_key" => "app-xxxxxx",
8
- "json" => "{\"name\" =>\"TotallyAwesomeProject\"}",
9
- "method" => "new",
10
- "object" => "project",
11
- "subscription_key" => "sub-xxxxxx"
12
- },
13
- "response" => {
14
- "project" => {
15
- "admins" => [],
16
- "api_key" => "6xxxxxxxxx58xx0xxx74xx3x76xx83x6x34xx48x7xxxx55x167037818d65x66x",
17
- "created_at" => "2011-10-25 00:43:49",
18
- "default_domain" => "awe.sm",
19
- "domains" => [],
20
- "name" => "TotallyAwesomeProject",
21
- "sharers" => [],
22
- "updated_at" => "2011-10-25 00:43:49",
23
- "viewers" => []
24
- }
25
- }
26
- }.to_json
27
- end
28
-
29
- let(:json_error_response) do
30
- {
31
- "request" => {
32
- "application_key" => "app-xxxxxx",
33
- "json" => "{\"name\" =>\"ExistingAwesomeProject\"}",
34
- "method" => "new",
35
- "object" => "project",
36
- "subscription_key" => "sub-xxxxxx"
37
- },
38
- "error" => {
39
- "code" => 10001,
40
- "message" => "Project name already exists (not necessarily in your subscription). Please choose another."
41
- }
42
- }.to_json
43
- end
44
4
 
45
5
  before do
46
6
  Awesm.subscription_key = 'sub-xxxxxx'
47
7
  Awesm.application_key = 'app-xxxxxx'
48
- stub_request(:post, "http://api.awe.sm/projects/new?json=%7B%22name%22:%22TotallyAwesomeProject%22%7D&subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
49
- to_return(:status => 200, :body => json_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
50
- stub_request(:post, "http://api.awe.sm/projects/new?json=%7B%22name%22:%22ExistingAwesomeProject%22%7D&subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
51
- to_return(:status => 400, :body => json_error_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
52
8
  end
9
+
53
10
  after do
54
11
  Awesm.subscription_key = nil
55
12
  Awesm.application_key = nil
56
13
  end
57
14
 
58
15
  context '.create' do
16
+ let(:json_response) do
17
+ {
18
+ "request" => {
19
+ "application_key" => "app-xxxxxx",
20
+ "json" => "{\"name\" =>\"TotallyAwesomeProject\"}",
21
+ "method" => "new",
22
+ "object" => "project",
23
+ "subscription_key" => "sub-xxxxxx"
24
+ },
25
+ "response" => {
26
+ "project" => {
27
+ "admins" => [],
28
+ "api_key" => "6xxxxxxxxx58xx0xxx74xx3x76xx83x6x34xx48x7xxxx55x167037818d65x66x",
29
+ "created_at" => "2011-10-25 00:43:49",
30
+ "default_domain" => "awe.sm",
31
+ "domains" => [],
32
+ "name" => "TotallyAwesomeProject",
33
+ "sharers" => [],
34
+ "updated_at" => "2011-10-25 00:43:49",
35
+ "viewers" => []
36
+ }
37
+ }
38
+ }.to_json
39
+ end
40
+
41
+ let(:json_error_response) do
42
+ {
43
+ "request" => {
44
+ "application_key" => "app-xxxxxx",
45
+ "json" => "{\"name\" =>\"ExistingAwesomeProject\"}",
46
+ "method" => "new",
47
+ "object" => "project",
48
+ "subscription_key" => "sub-xxxxxx"
49
+ },
50
+ "error" => {
51
+ "code" => 10001,
52
+ "message" => "Project name already exists (not necessarily in your subscription). Please choose another."
53
+ }
54
+ }.to_json
55
+ end
56
+
57
+ before do
58
+ stub_request(:post, "http://api.awe.sm/projects/new?json=%7B%22name%22:%22TotallyAwesomeProject%22%7D&subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
59
+ to_return(:status => 200, :body => json_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
60
+ stub_request(:post, "http://api.awe.sm/projects/new?json=%7B%22name%22:%22ExistingAwesomeProject%22%7D&subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
61
+ to_return(:status => 400, :body => json_error_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
62
+ end
63
+
59
64
  context 'when an error occurs' do
60
65
  it 'returns nil' do
61
66
  project = Awesm::Project.create(:name => "ExistingAwesomeProject")
@@ -79,7 +84,133 @@ describe Awesm::Project do
79
84
  end
80
85
  end
81
86
 
87
+ describe '.list' do
88
+ let(:json_response) do
89
+ {
90
+ "request" => {
91
+ "application_key" => "app-xxxxxx",
92
+ "method" => "list",
93
+ "object" => "project",
94
+ "subscription_key" => "sub-xxxxxx"
95
+ },
96
+ "response" => {
97
+ "projects" => [
98
+ {
99
+ "admins" => [
100
+ {
101
+ "default_project" => "demo",
102
+ "email" => "jeremiah@example.com",
103
+ "name" => "Jeremiah Lee",
104
+ "sharer_id" => "9496x4x0-20xx-012x-58xx-123139064x82",
105
+ "username" => "jeremiah"
106
+ }
107
+ ],
108
+ "api_key" => "x3x202x0151xxxx207x3xx99xxx3x6xx8x2x1d2xxxx5xx72899986xxxx1080x6",
109
+ "created_at" => "2010-04-02 23:15:59",
110
+ "default_domain" => "demo.awe.sm",
111
+ "domains" => [
112
+ "demo.awe.sm"
113
+ ],
114
+ "name" => "demo",
115
+ "sharers" => [
116
+ {
117
+ "default_project" => "bunyan_logging",
118
+ "email" => "paul@example.com",
119
+ "name" => "Paul Bunyan",
120
+ "sharer_id" => "8x58x4x0-39x5-012x-8109-123139064x82",
121
+ "username" => "pbunyan"
122
+ }
123
+ ],
124
+ "updated_at" => "2011-07-21 18:28:16",
125
+ "viewers" => [
126
+ {
127
+ "default_project" => "appleseeds_blog",
128
+ "email" => "jonny@example.com",
129
+ "name" => "Jonny Appleseed",
130
+ "sharer_id" => "9x69x9x0-42x1-420x-9876-123139064x99",
131
+ "username" => "jonny"
132
+ }
133
+ ]
134
+ }
135
+ ]
136
+ }
137
+ }.to_json
138
+ end
139
+
140
+ let(:json_error_response) do
141
+ {
142
+ "request" => {
143
+ "action" => "list",
144
+ "subscription_key" => "butt",
145
+ "application_key" => "tlVC3D",
146
+ "controller" => "project"
147
+ },
148
+ "error" => "Invalid subscription key"
149
+ }.to_json
150
+ end
151
+
152
+ before do
153
+ stub_request(:post, "http://api.awe.sm/projects/list?subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
154
+ to_return(:status => 200, :body => json_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
155
+ stub_request(:post, "http://api.awe.sm/projects/list?subscription_key=invalid&application_key=app-xxxxxx").
156
+ to_return(:status => 400, :body => json_error_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
157
+ end
158
+
159
+ it 'posts to the awe.sm project list api properly' do
160
+ Awesm::Project.list
161
+
162
+ a_request(:post, "http://api.awe.sm/projects/list").
163
+ with(:query => {:subscription_key => "sub-xxxxxx", :application_key => "app-xxxxxx"}).
164
+ should have_been_made.once
165
+ end
166
+
167
+ context 'when an error occurs' do
168
+ before { Awesm.subscription_key = 'invalid' }
169
+ it 'returns nil' do
170
+ project = Awesm::Project.list
171
+ project.should == nil
172
+ end
173
+ end
174
+
175
+ context 'when successful' do
176
+ it 'returns an array of Awesm:Project objects' do
177
+ projects = Awesm::Project.list
178
+ projects.first.should be_an_instance_of(Awesm::Project)
179
+ end
180
+ end
181
+ end
182
+
82
183
  describe '#api_key' do
184
+ let(:json_response) do
185
+ {
186
+ "request" => {
187
+ "application_key" => "app-xxxxxx",
188
+ "json" => "{\"name\" =>\"TotallyAwesomeProject\"}",
189
+ "method" => "new",
190
+ "object" => "project",
191
+ "subscription_key" => "sub-xxxxxx"
192
+ },
193
+ "response" => {
194
+ "project" => {
195
+ "admins" => [],
196
+ "api_key" => "6xxxxxxxxx58xx0xxx74xx3x76xx83x6x34xx48x7xxxx55x167037818d65x66x",
197
+ "created_at" => "2011-10-25 00:43:49",
198
+ "default_domain" => "awe.sm",
199
+ "domains" => [],
200
+ "name" => "TotallyAwesomeProject",
201
+ "sharers" => [],
202
+ "updated_at" => "2011-10-25 00:43:49",
203
+ "viewers" => []
204
+ }
205
+ }
206
+ }.to_json
207
+ end
208
+
209
+ before do
210
+ stub_request(:post, "http://api.awe.sm/projects/new?json=%7B%22name%22:%22TotallyAwesomeProject%22%7D&subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
211
+ to_return(:status => 200, :body => json_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
212
+ end
213
+
83
214
  it 'returns the awe.sm api_key' do
84
215
  project = Awesm::Project.create({ :name => "TotallyAwesomeProject" })
85
216
  project.api_key.should == '6xxxxxxxxx58xx0xxx74xx3x76xx83x6x34xx48x7xxxx55x167037818d65x66x'
@@ -2,7 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe Awesm::Url do
4
4
  describe '.share' do
5
- it 'returns the correct awe.sm url' do
5
+ let(:required_parameters) do
6
+ {
7
+ :url => 'http://developers.awe.sm/',
8
+ :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9',
9
+ :tool => 'mKU7uN',
10
+ :channel => 'twitter',
11
+ :destination => 'http://twitter.com/intent/tweet?text=This+is+the+coolest+API+evar!%26url=AWESM_URL%26via=awesm'
12
+ }
13
+ end
14
+
15
+ it 'returns the correct awe.sm url when passed the required parameters' do
6
16
  Awesm::Url.share(:url => 'http://developers.awe.sm/',
7
17
  :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9',
8
18
  :tool => 'mKU7uN',
@@ -11,9 +21,38 @@ describe Awesm::Url do
11
21
  should == 'http://api.awe.sm/url/share?v=3&url=http://developers.awe.sm/&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&tool=mKU7uN&channel=twitter&destination=http://twitter.com/intent/tweet?text=This+is+the+coolest+API+evar!%26url=AWESM_URL%26via=awesm'
12
22
  end
13
23
 
14
- it 'returns nil if no options are sent in' do
24
+ it 'returns nil if it receives an empty hash' do
15
25
  Awesm::Url.share({}).should == nil
16
26
  end
27
+
28
+ it 'returns nil if it receives nothing' do
29
+ Awesm::Url.share.should == nil
30
+ end
31
+
32
+ [[:campaign, 'my-campaign-1'],
33
+ [:campaign_description, 'This is a description. Fun.'],
34
+ [:campaign_name, 'My Campaign 1'],
35
+ [:notes, 'This link is going to take down my site.'],
36
+ [:parent, 'awe.sm_s5d99'],
37
+ [:service_userid, 'twitter:13263'],
38
+ [:tag, 'My-Tag'],
39
+ [:user_id, '42']].each do |option, value|
40
+ it "returns the correct awe.sm url when also passed a '#{option.to_s}' parameter" do
41
+ Awesm::Url.share(required_parameters.merge(option => value)).
42
+ should == "http://api.awe.sm/url/share?v=3&url=http://developers.awe.sm/&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&tool=mKU7uN&channel=twitter&destination=http://twitter.com/intent/tweet?text=This+is+the+coolest+API+evar!%26url=AWESM_URL%26via=awesm&#{option.to_s}=#{value}"
43
+ end
44
+ end
45
+
46
+ it "accepts user_id related parameters" do
47
+ url = Awesm::Url.share(required_parameters.merge(
48
+ :user_id => 42,
49
+ :user_id_icon_url => 'http://test.com/users/42/avatar.png',
50
+ :user_id_profile_url => 'http://test.com/users/42/',
51
+ :user_id_username => 'johndoe@test.com'
52
+ ))
53
+ url.should == "http://api.awe.sm/url/share?v=3&url=http://developers.awe.sm/&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&tool=mKU7uN&channel=twitter&destination=http://twitter.com/intent/tweet?text=This+is+the+coolest+API+evar!%26url=AWESM_URL%26via=awesm&user_id_icon_url=http://test.com/users/42/avatar.png&user_id_profile_url=http://test.com/users/42/&user_id_username=johndoe@test.com&user_id=42"
54
+ end
55
+
17
56
  end
18
57
  end
19
58
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sathya Sekaran
@@ -19,8 +19,8 @@ cert_chain: []
19
19
  date: 2011-12-08 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rake
23
22
  prerelease: false
23
+ type: :development
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
@@ -30,11 +30,11 @@ dependencies:
30
30
  segments:
31
31
  - 0
32
32
  version: "0"
33
- type: :development
33
+ name: rake
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: rspec
37
36
  prerelease: false
37
+ type: :development
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
@@ -44,11 +44,11 @@ dependencies:
44
44
  segments:
45
45
  - 0
46
46
  version: "0"
47
- type: :development
47
+ name: rspec
48
48
  version_requirements: *id002
49
49
  - !ruby/object:Gem::Dependency
50
- name: webmock
51
50
  prerelease: false
51
+ type: :development
52
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
@@ -58,11 +58,11 @@ dependencies:
58
58
  segments:
59
59
  - 0
60
60
  version: "0"
61
- type: :development
61
+ name: webmock
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: httparty
65
64
  prerelease: false
65
+ type: :development
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
@@ -72,11 +72,11 @@ dependencies:
72
72
  segments:
73
73
  - 0
74
74
  version: "0"
75
- type: :development
75
+ name: httparty
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency
78
- name: json
79
78
  prerelease: false
79
+ type: :development
80
80
  requirement: &id005 !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -86,11 +86,11 @@ dependencies:
86
86
  segments:
87
87
  - 0
88
88
  version: "0"
89
- type: :development
89
+ name: json
90
90
  version_requirements: *id005
91
91
  - !ruby/object:Gem::Dependency
92
- name: hashie
93
92
  prerelease: false
93
+ type: :development
94
94
  requirement: &id006 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
@@ -100,11 +100,11 @@ dependencies:
100
100
  segments:
101
101
  - 0
102
102
  version: "0"
103
- type: :development
103
+ name: hashie
104
104
  version_requirements: *id006
105
105
  - !ruby/object:Gem::Dependency
106
- name: ruby-debug
107
106
  prerelease: false
107
+ type: :development
108
108
  requirement: &id007 !ruby/object:Gem::Requirement
109
109
  none: false
110
110
  requirements:
@@ -114,11 +114,11 @@ dependencies:
114
114
  segments:
115
115
  - 0
116
116
  version: "0"
117
- type: :development
117
+ name: ruby-debug
118
118
  version_requirements: *id007
119
119
  - !ruby/object:Gem::Dependency
120
- name: httparty
121
120
  prerelease: false
121
+ type: :runtime
122
122
  requirement: &id008 !ruby/object:Gem::Requirement
123
123
  none: false
124
124
  requirements:
@@ -128,11 +128,11 @@ dependencies:
128
128
  segments:
129
129
  - 0
130
130
  version: "0"
131
- type: :runtime
131
+ name: httparty
132
132
  version_requirements: *id008
133
133
  - !ruby/object:Gem::Dependency
134
- name: json
135
134
  prerelease: false
135
+ type: :runtime
136
136
  requirement: &id009 !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
@@ -142,11 +142,11 @@ dependencies:
142
142
  segments:
143
143
  - 0
144
144
  version: "0"
145
- type: :runtime
145
+ name: json
146
146
  version_requirements: *id009
147
147
  - !ruby/object:Gem::Dependency
148
- name: hashie
149
148
  prerelease: false
149
+ type: :runtime
150
150
  requirement: &id010 !ruby/object:Gem::Requirement
151
151
  none: false
152
152
  requirements:
@@ -156,7 +156,7 @@ dependencies:
156
156
  segments:
157
157
  - 0
158
158
  version: "0"
159
- type: :runtime
159
+ name: hashie
160
160
  version_requirements: *id010
161
161
  description: The 'awesm' gem is an interface for awe.sm (http://totally.awe.sm), a social link analytics tracking service.
162
162
  email:
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  requirements: []
216
216
 
217
217
  rubyforge_project: awesm
218
- rubygems_version: 1.8.12
218
+ rubygems_version: 1.8.10
219
219
  signing_key:
220
220
  specification_version: 3
221
221
  summary: Totally awe.sm!