awesm 0.1.7 → 0.1.8

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/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .DS_Store
6
+ tags
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Awesm #
2
2
 
3
- The *awesm* gem is an easy way to access the awe.sm API (http://totally.awe.sm).
3
+ The *awesm* gem is an easy way to access the awe.sm API (http://developers.awe.sm).
4
+
5
+ You can find the YARD documentation for the latest release here: http://rdoc.info/github/sfsekaran/awesm/frames
4
6
 
5
7
  We're actively developing this (and it's not yet production ready) but please
6
- feel free to send us a pull request from a topic branch with specs and an
7
- explanation :)
8
+ feel free to send us a pull request from a topic branch with specs,
9
+ documentation, and an explanation :)
8
10
 
9
11
  ## Usage ##
10
12
 
@@ -19,17 +21,47 @@ And in your code:
19
21
  Awesm.application_key = 'app-xxxxxx'
20
22
 
21
23
  # Create a project
22
- project = Awesm::Project.create(:name => 'TotallyAwesm')
24
+ project = Awesm::Project.create({
25
+ :name => "myNewProject",
26
+ :domains => [
27
+ "examp.le",
28
+ "demo.examp.le"
29
+ ],
30
+ :default_domain => "examp.le",
31
+ :admins => [
32
+ "jeremiah"
33
+ ],
34
+ :sharers => [
35
+ "paul@example.com"
36
+ ],
37
+ :viewers => [
38
+ "9x69x9x0-42x1-420x-9876-123139064x99"
39
+ ],
40
+ :conversions => {
41
+ :enabled => true,
42
+ :domains => [
43
+ "example.com",
44
+ "www.example.com",
45
+ "example.net"
46
+ ],
47
+ :goal_1_label => "Liked our Facebook Page",
48
+ :goal_2_label => "Downloaded Photo of the Day",
49
+ :goal_3_label => "Purchase"
50
+ }
51
+ })
23
52
  project.api_key # => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9'
24
53
  # or
25
54
  project = Awesm::Project.new(:name => 'TotallyAwesm')
26
55
  project.save # => true
27
- project.api_key # => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9'
56
+ project.api_key # => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045e9'
28
57
 
29
58
  # List projects
30
59
  projects = Awesm::Project.list
31
60
  projects.first.class # => Awesm::Project
32
61
 
62
+ # Delete a project
63
+ project.destroy # => true
64
+
33
65
  # Notify Awe.sm of a goal conversion
34
66
  Awesm::Conversion.convert(
35
67
  :key => "f2d8aeb112f1e0bedd7c05653e3265d2622635a3180f336f73b172267f7fe6ee",
@@ -51,6 +83,15 @@ And in your code:
51
83
  )
52
84
  # => "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"
53
85
 
86
+ # Create a static link
87
+ Awesm::Url.static(
88
+ :format => 'json',
89
+ :url => 'http://developers.awe.sm/',
90
+ :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9',
91
+ :tool => 'mKU7uN'
92
+ )
93
+ # => "http://api.awe.sm/url/static.json?v=3&url=http://developers.awe.sm/&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&tool=mKU7uN"
94
+
54
95
  # Retrieve stats in return for your hard work!
55
96
  stats = Awesm::Stats.range(
56
97
  :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9',
@@ -59,13 +100,19 @@ And in your code:
59
100
  )
60
101
  stats.totals.clicks # => 1024
61
102
 
103
+ url_stats = Awesm::Stats.url(
104
+ :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9',
105
+ :awesm_id => 'demo.awe.sm_K7e'
106
+ )
107
+ url_stats.clicks # => 256
108
+
62
109
  ## Contributing ##
63
110
 
64
111
  * fork
65
112
  * clone
66
113
  * bundle install
67
114
  * bundle exec rspec spec
68
- * commit code with passing specs
115
+ * commit code with passing specs and documentation
69
116
  * push to a topic branch
70
117
  * send us a pull request :)
71
118
 
@@ -2,6 +2,7 @@ module Awesm
2
2
  class Project < Hashie::Mash
3
3
  include HTTParty
4
4
  base_uri 'http://api.awe.sm/projects'
5
+ format :json
5
6
 
6
7
  def self.create(attributes)
7
8
  project = self.new(attributes)
@@ -36,5 +37,10 @@ module Awesm
36
37
  true
37
38
  end
38
39
  end
40
+
41
+ def destroy
42
+ response = self.class.post("/#{api_key}/destroy", :query => { :application_key => Awesm.application_key, :subscription_key => Awesm.subscription_key })
43
+ true unless response.has_key?('error')
44
+ end
39
45
  end
40
46
  end
@@ -6,11 +6,13 @@ module Awesm
6
6
 
7
7
  def self.range(options)
8
8
  response = get '/range.json', :query => { :v => 3 }.merge(options)
9
- if response.has_key?('error')
10
- nil
11
- else
12
- new(response)
13
- end
9
+ new(response)
10
+ end
11
+
12
+ def self.url(options)
13
+ awesm_id = options.delete(:awesm_id)
14
+ response = get "/#{awesm_id}.json", :query => { :v => 3 }.merge(options)
15
+ new(response)
14
16
  end
15
17
  end
16
18
  end
@@ -1,9 +1,10 @@
1
1
  module Awesm
2
2
  class Url
3
3
  REQUIRED_SHARE_PARAMS = [:url, :key, :tool, :channel, :destination].freeze
4
+ REQUIRED_STATIC_PARAMS = [:format, :url, :key, :tool].freeze
4
5
 
5
6
  def self.share(params = {})
6
- if required_params_present_for_share?(params)
7
+ if required_params_present?(REQUIRED_SHARE_PARAMS, params)
7
8
  options = params.clone
8
9
  options = options.delete_if{|key,value| REQUIRED_SHARE_PARAMS.include?(key) }
9
10
  query = options.map{|k,v| "#{k}=#{v}"}.join('&')
@@ -13,8 +14,19 @@ module Awesm
13
14
  end
14
15
  end
15
16
 
16
- def self.required_params_present_for_share?(params)
17
- REQUIRED_SHARE_PARAMS.all? do |param|
17
+ def self.static(params = {})
18
+ if required_params_present?(REQUIRED_STATIC_PARAMS, params)
19
+ options = params.clone
20
+ options = options.delete_if{|key,value| REQUIRED_STATIC_PARAMS.include?(key) }
21
+ query = options.map{|k,v| "#{k}=#{v}"}.join('&')
22
+ static_url = "http://api.awe.sm/url/static.#{params[:format]}?v=3&url=#{params[:url]}&key=#{params[:key]}&tool=#{params[:tool]}"
23
+ static_url += "&#{query}" if query.length > 0
24
+ static_url
25
+ end
26
+ end
27
+
28
+ def self.required_params_present?(required_params, params)
29
+ required_params.all? do |param|
18
30
  params.include?(param)
19
31
  end
20
32
  end
@@ -1,3 +1,3 @@
1
1
  module Awesm
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -53,6 +53,21 @@ describe Awesm::Project do
53
53
  }.to_json
54
54
  end
55
55
 
56
+ let(:delete_project_response) do
57
+ {
58
+ :request => {
59
+ :apikey => "9x863xx7xx12x56433059xx8091838f5f5589x71x04f4760490x6x79xx9xx681",
60
+ :subscription_key => "sub-xxxxxx",
61
+ :application_key => "app-xxxxxx",
62
+ :object => "project",
63
+ :method => "delete"
64
+ },
65
+ :response => {
66
+ :deleted => true
67
+ }
68
+ }.to_json
69
+ end
70
+
56
71
  context '.create' do
57
72
  before do
58
73
  stub_request(:post, "http://api.awe.sm/projects/new?json=%7B%22name%22:%22TotallyAwesomeProject%22%7D&subscription_key=sub-xxxxxx&application_key=app-xxxxxx").
@@ -136,6 +151,27 @@ describe Awesm::Project do
136
151
  it 'does not update a project in awe.sm if it exists and attributes have not changed'
137
152
  end
138
153
 
154
+ describe "#destroy" do
155
+ let(:existing_project) { Awesm::Project.new(:name => 'ExistingAwesomeProject', :api_key => '9x863xx7xx12x56433059xx8091838f5f5589x71x04f4760490x6x79xx9xx681') }
156
+
157
+ before do
158
+ stub_request(:post, "http://api.awe.sm/projects/9x863xx7xx12x56433059xx8091838f5f5589x71x04f4760490x6x79xx9xx681/destroy?application_key=app-xxxxxx&subscription_key=sub-xxxxxx").
159
+ to_return(:status => 200, :body => delete_project_response, :headers => {})
160
+ end
161
+
162
+ it 'posts to the project destroy api' do
163
+ existing_project.destroy
164
+
165
+ a_request(:post, "http://api.awe.sm/projects/#{existing_project.api_key}/destroy").
166
+ with(:query => {:subscription_key => "sub-xxxxxx", :application_key => "app-xxxxxx"}).
167
+ should have_been_made.once
168
+ end
169
+
170
+ it 'returns true on success' do
171
+ existing_project.destroy.should == true
172
+ end
173
+ end
174
+
139
175
  describe '.list' do
140
176
  let(:list_project_response) do
141
177
  {
@@ -1,6 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Awesm::Stats do
4
+ let(:invalid_key_response) do
5
+ {
6
+ "error" => 403,
7
+ "error_message" => "Invalid API key specified"
8
+ }.to_json
9
+ end
10
+
4
11
  describe '.range' do
5
12
  let(:basic_response) do
6
13
  {
@@ -30,13 +37,6 @@ describe Awesm::Stats do
30
37
  }.to_json
31
38
  end
32
39
 
33
- let(:invalid_key_response) do
34
- {
35
- "error" => 403,
36
- "error_message" => "Invalid API key specified"
37
- }.to_json
38
- end
39
-
40
40
  before do
41
41
  stub_request(:get, "http://api.awe.sm/stats/range.json?v=3&end_date=2011-10-01&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&start_date=2011-09-01").
42
42
  to_return(:status => 200, :body => basic_response, :headers => { 'Content-Type' => 'application/json;charset=utf-8' })
@@ -72,13 +72,22 @@ describe Awesm::Stats do
72
72
  should have_been_made.once
73
73
  end
74
74
 
75
- it 'gets with an incorrect key' do
75
+ it 'returns an error code when using an incorrect key' do
76
76
  stats = Awesm::Stats.range(
77
77
  :key => 'fake_key',
78
78
  :start_date => '2011-09-01',
79
79
  :end_date => '2011-10-01'
80
80
  )
81
- stats.should == nil
81
+ stats.error.should == 403
82
+ end
83
+
84
+ it 'returns an error code when using an incorrect key' do
85
+ stats = Awesm::Stats.range(
86
+ :key => 'fake_key',
87
+ :start_date => '2011-09-01',
88
+ :end_date => '2011-10-01'
89
+ )
90
+ stats.error_message.should == 'Invalid API key specified'
82
91
  end
83
92
 
84
93
  it 'returns an instance of Awesm::Stats' do
@@ -90,4 +99,51 @@ describe Awesm::Stats do
90
99
  stats.should be_an_instance_of(Awesm::Stats)
91
100
  end
92
101
  end
102
+
103
+ describe '.url' do
104
+ let(:stats_response) do
105
+ {
106
+ "awesm_id" => "demo.awe.sm_K7e",
107
+ "clicks" => 5,
108
+ "end_date" => nil,
109
+ "interval" => "none",
110
+ "start_date" => nil,
111
+ "with_conversions" => false,
112
+ "with_metadata" => false,
113
+ "with_zeros" => false
114
+ }.to_json
115
+ end
116
+
117
+ before do
118
+ stub_request(:get, "http://api.awe.sm/stats/demo.awe.sm_K7e.json").
119
+ with(:query => { :v => '3', :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9' }).
120
+ to_return(:status => 200, :body => stats_response, :headers => {})
121
+ stub_request(:get, "http://api.awe.sm/stats/demo.awe.sm_K7e.json").
122
+ with(:query => { :v => '3', :key => 'wrong' }).
123
+ to_return(:status => 200, :body => invalid_key_response, :headers => {})
124
+ end
125
+
126
+ it 'should make the correct api call' do
127
+ Awesm::Stats.url(:key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9', :awesm_id => 'demo.awe.sm_K7e')
128
+
129
+ a_request(:get, 'http://api.awe.sm/stats/demo.awe.sm_K7e.json').
130
+ with(:query => { :v => '3', :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9' }).
131
+ should have_been_made.once
132
+ end
133
+
134
+ it 'should return an instance of Awesm::Stats' do
135
+ stats = Awesm::Stats.url(:key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9', :awesm_id => 'demo.awe.sm_K7e')
136
+ stats.should be_an_instance_of(Awesm::Stats)
137
+ end
138
+
139
+ it 'should return an error code with incorrect request info' do
140
+ stats = Awesm::Stats.url(:key => 'wrong', :awesm_id => 'demo.awe.sm_K7e')
141
+ stats.error.should == 403
142
+ end
143
+
144
+ it 'should return an error message with incorrect request info' do
145
+ stats = Awesm::Stats.url(:key => 'wrong', :awesm_id => 'demo.awe.sm_K7e')
146
+ stats.error_message.should == 'Invalid API key specified'
147
+ end
148
+ end
93
149
  end
@@ -54,5 +54,58 @@ describe Awesm::Url do
54
54
  end
55
55
 
56
56
  end
57
+
58
+ describe '.static' do
59
+ let(:required_parameters) do
60
+ {
61
+ :format => 'json',
62
+ :url => 'http://developers.awe.sm/',
63
+ :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9',
64
+ :tool => 'mKU7uN'
65
+ }
66
+ end
67
+
68
+ it 'returns the correct static awe.sm url when passed the required parameters' do
69
+ Awesm::Url.static(:format => 'json',
70
+ :url => 'http://developers.awe.sm/',
71
+ :key => '5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9',
72
+ :tool => 'mKU7uN').
73
+ should == 'http://api.awe.sm/url/static.json?v=3&url=http://developers.awe.sm/&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&tool=mKU7uN'
74
+ end
75
+
76
+ it 'returns nil if it receives an empty hash' do
77
+ Awesm::Url.static({}).should == nil
78
+ end
79
+
80
+ it 'returns nil if it receives nothing' do
81
+ Awesm::Url.static.should == nil
82
+ end
83
+
84
+ [[:channel, 'twitter'],
85
+ [:campaign, 'my-campaign-1'],
86
+ [:campaign_description, 'This is a description. Fun.'],
87
+ [:campaign_name, 'My Campaign 1'],
88
+ [:notes, 'This link is going to take down my site.'],
89
+ [:parent, 'awe.sm_s5d99'],
90
+ [:service_userid, 'twitter:13263'],
91
+ [:tag, 'My-Tag'],
92
+ [:user_id, '42']].each do |option, value|
93
+ it "returns the correct static awe.sm url when also passed a '#{option.to_s}' parameter" do
94
+ Awesm::Url.static(required_parameters.merge(option => value)).
95
+ should == "http://api.awe.sm/url/static.json?v=3&url=http://developers.awe.sm/&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&tool=mKU7uN&#{option.to_s}=#{value}"
96
+ end
97
+ end
98
+
99
+ it "accepts user_id related parameters" do
100
+ url = Awesm::Url.static(required_parameters.merge(
101
+ :user_id => 42,
102
+ :user_id_icon_url => 'http://test.com/users/42/avatar.png',
103
+ :user_id_profile_url => 'http://test.com/users/42/',
104
+ :user_id_username => 'johndoe@test.com'
105
+ ))
106
+ url.should == "http://api.awe.sm/url/static.json?v=3&url=http://developers.awe.sm/&key=5c8b1a212434c2153c2f2c2f2c765a36140add243bf6eae876345f8fd11045d9&tool=mKU7uN&user_id=42&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"
107
+ end
108
+
109
+ end
57
110
  end
58
111
 
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: 21
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sathya Sekaran
@@ -16,11 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-12-14 00:00:00 Z
19
+ date: 2012-04-21 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ name: rake
22
23
  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
- name: rake
33
+ type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
+ name: rspec
36
37
  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
- name: rspec
47
+ type: :development
48
48
  version_requirements: *id002
49
49
  - !ruby/object:Gem::Dependency
50
+ name: webmock
50
51
  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
- name: webmock
61
+ type: :development
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
+ name: httparty
64
65
  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
- name: httparty
75
+ type: :development
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency
78
+ name: json
78
79
  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
- name: json
89
+ type: :development
90
90
  version_requirements: *id005
91
91
  - !ruby/object:Gem::Dependency
92
+ name: hashie
92
93
  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
- name: hashie
103
+ type: :development
104
104
  version_requirements: *id006
105
105
  - !ruby/object:Gem::Dependency
106
+ name: ruby-debug
106
107
  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
- name: ruby-debug
117
+ type: :development
118
118
  version_requirements: *id007
119
119
  - !ruby/object:Gem::Dependency
120
+ name: httparty
120
121
  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
- name: httparty
131
+ type: :runtime
132
132
  version_requirements: *id008
133
133
  - !ruby/object:Gem::Dependency
134
+ name: json
134
135
  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
- name: json
145
+ type: :runtime
146
146
  version_requirements: *id009
147
147
  - !ruby/object:Gem::Dependency
148
+ name: hashie
148
149
  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
- name: hashie
159
+ type: :runtime
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:
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  requirements: []
218
218
 
219
219
  rubyforge_project: awesm
220
- rubygems_version: 1.8.10
220
+ rubygems_version: 1.8.23
221
221
  signing_key:
222
222
  specification_version: 3
223
223
  summary: Totally awe.sm!