mbsy 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mbsy (1.0.0)
4
+ mbsy (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -9,6 +9,13 @@ GEM
9
9
  activesupport (3.2.6)
10
10
  i18n (~> 0.6)
11
11
  multi_json (~> 1.0)
12
+ columnize (0.3.6)
13
+ debugger (1.5.0)
14
+ columnize (>= 0.3.1)
15
+ debugger-linecache (~> 1.2.0)
16
+ debugger-ruby_core_source (~> 1.2.0)
17
+ debugger-linecache (1.2.0)
18
+ debugger-ruby_core_source (1.2.0)
12
19
  diff-lcs (1.1.3)
13
20
  factory_girl (2.1.2)
14
21
  activesupport
@@ -23,7 +30,7 @@ GEM
23
30
  multi_json (1.3.6)
24
31
  multi_xml (0.5.1)
25
32
  rake (0.9.2.2)
26
- rb-fsevent (0.4.3.1)
33
+ rb-fsevent (0.9.3)
27
34
  rspec (2.7.0)
28
35
  rspec-core (~> 2.7.0)
29
36
  rspec-expectations (~> 2.7.0)
@@ -43,13 +50,14 @@ PLATFORMS
43
50
 
44
51
  DEPENDENCIES
45
52
  bundler (~> 1.1.1)
53
+ debugger
46
54
  factory_girl (~> 2.1.0)
47
55
  faker (~> 1.0.1)
48
56
  fakeweb (~> 1.3.0)
49
57
  httparty (~> 0.8.3)
50
- json
58
+ json (~> 1.7.3)
51
59
  mbsy!
52
60
  rake (~> 0.9.2)
53
- rb-fsevent (~> 0.4.2)
61
+ rb-fsevent (~> 0.9.3)
54
62
  rspec (~> 2.7.0)
55
63
  shoulda
data/README.md CHANGED
@@ -6,7 +6,7 @@ This is a lightweight Ruby wrapper for the [Ambassador](http://getambassador.com
6
6
 
7
7
  ### Installation
8
8
 
9
- This library can be installed as a gem. It is hosted on [Rubygems](http://rubygems.org).
9
+ This library can be installed as a gem. It is hosted on [Rubygems](https://rubygems.org/gems/mbsy).
10
10
 
11
11
  You can install this library as a gem using the following command:
12
12
 
@@ -40,8 +40,8 @@ Make sure you include your api credentials in an initialiser.
40
40
 
41
41
  ```ruby
42
42
  Mbsy.configure do |c|
43
- c.api_key 'MY_API_KEY'
44
- c.user_name 'MY_USER_NAME'
43
+ c.api_key = 'MY_API_KEY'
44
+ c.user_name = 'MY_USER_NAME'
45
45
  end
46
46
  ```
47
47
 
@@ -51,6 +51,39 @@ The mbsy gem will give you access to classes such as:
51
51
  * `Mbsy::Ambassador`
52
52
  * `Mbsy::Shortcode`
53
53
 
54
+ Some examples:
55
+
56
+ ```ruby
57
+ # Add 50 to user account
58
+ Mbsy::Balance.update(:add,{:email => 'example@example.com', :amount => 50})
59
+
60
+ # Deduct 25 from user account
61
+ Mbsy::Balance.update(:deduct,{:email => 'example@example.com', :amount => 25})
62
+
63
+ # Get company details
64
+ Mbsy::Company.get_details
65
+
66
+ # Register a referral event
67
+ # Note the email address is the new customer email, not the ambassador
68
+ # Autocreate flag sets whether they are created as a new ambassador or not
69
+ Mbsy::Event.create({:email => 'example@example.com', :short_code => REFERRALSHORTCODE, :campaign_uid => YOURCAMPAIGNUID, :auto_create => 0})
70
+
71
+ # Register a revenue event for an ambassador
72
+ Mbsy::Event.create({:email => 'example@example.com', :short_code => REFERRALSHORTCODE, :revenue => 120, :campaign_uid => YOURCAMPAIGNUID})
73
+
74
+ # Register a revenue event for an ambassador
75
+ # in this case, the email is for a previously registered referred customer, so no short code is required
76
+ Mbsy::Event.create({:email => 'example@example.com', :revenue => 120, :campaign_uid => YOURCAMPAIGNUID})
77
+
78
+ # Get the details on a shortcode
79
+ Mbsy::Shortcode.find({ :short_code => YOURCAMPAIGNUID })
80
+
81
+ # Shortcode in a sandbox campaign
82
+ Mbsy::Shortcode.find({ :short_code => YOURCAMPAIGNUID, :sandbox => 1 })
83
+
84
+
85
+ ```
86
+
54
87
  ### Contributing to mbsy
55
88
 
56
89
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -58,7 +91,7 @@ The mbsy gem will give you access to classes such as:
58
91
  * Fork the project.
59
92
  * Start a feature/bugfix branch.
60
93
  * Commit and push until you are happy with your contribution.
61
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
94
+ * Make sure to add tests for it. This is important so we don't break it in a future version unintentionally.
62
95
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
63
96
 
64
97
  ### To Do
data/lib/mbsy.rb CHANGED
@@ -5,6 +5,7 @@ require 'mbsy/resources/ambassador'
5
5
  require 'mbsy/resources/balance'
6
6
  require 'mbsy/resources/company'
7
7
  require 'mbsy/resources/event'
8
+ require 'mbsy/resources/group'
8
9
  require 'mbsy/resources/shortcode'
9
10
  require 'mbsy/resources/social'
10
11
 
@@ -18,4 +19,4 @@ module Mbsy
18
19
  end
19
20
  end
20
21
  end
21
- end
22
+ end
@@ -1,4 +1,6 @@
1
1
  module Mbsy
2
+ class RecordNotFound < Exception; end
3
+ class BadResponse < Exception; end
2
4
  class Base
3
5
  include HTTParty
4
6
  format :json
@@ -13,9 +15,12 @@ module Mbsy
13
15
  api_url = Mbsy.site_uri + self.element_name + '/' + method
14
16
 
15
17
  response = JSON.parse(self.get(api_url, :query => params).body)['response']
16
-
17
- if response["code"] != '200'
18
- raise "Error from Ambassador API: #{response["errors"]["error"]} (code #{response["code"]})"
18
+ case response['code']
19
+ when "200" # Nothing to do here...
20
+ when "404"
21
+ raise RecordNotFound.new(response["errors"]["error"])
22
+ else
23
+ raise BadResponse.new(response: response)
19
24
  end
20
25
 
21
26
  response['data']
@@ -0,0 +1,14 @@
1
+ module Mbsy
2
+ class Group < Base
3
+
4
+ def self.find(params={})
5
+ raise ArgumentError, "You must include :group_id" unless params[:group_id]
6
+ call('get', params)
7
+ end
8
+
9
+ def self.all(params={})
10
+ call('all', params)
11
+ end
12
+
13
+ end
14
+ end
data/mbsy.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mbsy'
3
- s.version = '1.0.1'
4
- s.date = '2013-02-22'
3
+ s.version = '1.0.2'
4
+ s.date = '2013-03-28'
5
5
  s.summary = 'A Ruby wrapper for the Ambassador API'
6
6
  s.description = ''
7
7
  s.author = 'Tom Mullen, Chase Lee'
@@ -19,9 +19,10 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency('factory_girl', '~> 2.1.0')
20
20
  s.add_development_dependency('fakeweb', '~> 1.3.0')
21
21
  s.add_development_dependency('faker', '~> 1.0.1')
22
- s.add_development_dependency('rb-fsevent', '~> 0.4.2')
22
+ s.add_development_dependency('rb-fsevent', '~> 0.9.3')
23
23
  s.add_development_dependency("shoulda", ">= 0")
24
24
  s.add_development_dependency("bundler", "~> 1.1.1")
25
25
  s.add_development_dependency('httparty', '~> 0.8.3')
26
26
  s.add_development_dependency('json', '~> 1.7.3')
27
- end
27
+ s.add_development_dependency('debugger', '~> 1.5.0')
28
+ end
@@ -4,40 +4,54 @@ require 'ruby-debug'
4
4
  describe Mbsy::Ambassador do
5
5
 
6
6
  let(:resource_prefix) { "#{fake_domain}/ambassadors" }
7
- let(:existing_ambassador) { Mbsy::Ambassador.find(email: 'ambassador@mbsy.co', first_name: 'sigma') }
7
+ before do
8
+ @existing_ambassador_response = Mbsy::Ambassador.find(email: 'ambassador@mbsy.co', first_name: 'sigma')
9
+ end
8
10
 
9
11
  context 'find existing ambassador' do
10
- before do
11
- FakeWeb.register_uri(:get, "#{resource_prefix}/get/", :query => existing_ambassador.attributes)
12
- end
13
-
14
- it 'is an instance of Mbsy::Ambassador' do
15
- debugger
16
- ambassador = Mbsy::Ambassador.find(email: 'ambassador@mbsy.co')
12
+ subject { Mbsy::Ambassador.find(email: 'ambassador@mbsy.co') }
13
+ pending 'is an instance of Mbsy::Ambassador' do
17
14
  ambassador.should be_instance_of(Mbsy::Ambassador)
18
15
  end
19
-
20
- it 'finds the correct ambassdor by email' do
21
- ambassador = Mbsy::Ambassador.find(email: 'ambassador@mbsy.co')
22
- ambassador.email.should eq(existing_ambassador.email)
16
+ it { should be_instance_of(Hash) }
17
+ it { should have_key('ambassador') }
18
+ it { should == @existing_ambassador_response }
19
+
20
+ it 'should return an ambassador with the same email' do
21
+ subject['ambassador']['email'].should == @existing_ambassador_response['ambassador']['email']
23
22
  end
24
-
25
- it 'creates the ambassador if you cannot find one' do
26
- ambassador = Mbsy::Ambassador.find(email: 'ambassador@mbsy.co', first_name: 'tester')
27
- ambassador.first_name.should eq('tester')
23
+ end
24
+ context 'existing ambassador not found' do
25
+ before do
26
+ # Stub out creation call since this is hitting a live service
27
+ FakeWeb.register_uri(:get, "#{resource_prefix}/get/", query: {email: 'new_ambassador@mbsy.co', first_name: 'tester'}, response: File.expand_path('spec/fixtures/ambassador_response_v2.json') )
28
+ end
29
+ pending 'creates the ambassador if you cannot find one' do
30
+ # Need a proper stubbed response before this can work
31
+ ambassador = Mbsy::Ambassador.find(email: 'new_ambassador@mbsy.co', first_name: 'tester')
32
+ ambassador['ambassador']['first_name'].should eq('tester')
33
+ end
34
+ context 'failed lookup without auto-create' do
35
+ it "should raise a RecordNotFound error " do
36
+ lambda{
37
+ Mbsy::Ambassador.find(email: 'not_found@mbsy.co', auto_create: 0)
38
+ }.should raise_error(Mbsy::RecordNotFound)
39
+ end
28
40
  end
29
41
  end
30
42
 
31
43
  it 'returns a list of all ambassadors' do
32
- FakeWeb.register_uri(:get, "#{resource_prefix}/all/", :query => existing_ambassador.attributes)
33
- ambassadors = Mbsy::Ambassador.all
34
- ambassadors.should include(existing_ambassador)
44
+ all_response = Mbsy::Ambassador.all
45
+ ambassadors = all_response['ambassadors']
46
+ ambassadors.length.should > 0
47
+ existing_ambassador_in_response = ambassadors.detect{|a| a['email'] == @existing_ambassador_response['ambassador']['email'] }
48
+ existing_ambassador_in_response.should_not be_nil
49
+ existing_ambassador_in_response['first_name'].should == 'sigma'
35
50
  end
36
51
 
37
- it 'returns a list of all ambassadors' do
38
- FakeWeb.register_uri(:get, "#{resource_prefix}/stats/", :query => existing_ambassador.attributes)
39
- ambassador = Mbsy::Ambassador.find(email: 'ambassador@mbsy.co')
40
- ambassador.email.should eq(existing_ambassador.email)
52
+ it 'returns stats on an existing ambassador' do
53
+ ambassador = Mbsy::Ambassador.stats(email: 'ambassador@mbsy.co')
54
+ ambassador['ambassador']['email'].should eq(@existing_ambassador_response['ambassador']['email'])
41
55
  end
42
56
 
43
- end
57
+ end
data/spec/spec_helper.rb CHANGED
@@ -26,5 +26,5 @@ RSpec.configure do |config|
26
26
  end
27
27
 
28
28
  def fake_domain
29
- "https://#{Mbsy.site_uri}/"
29
+ "#{Mbsy.site_uri}/"
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 0.4.2
101
+ version: 0.9.3
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: 0.4.2
109
+ version: 0.9.3
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: shoulda
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -171,6 +171,22 @@ dependencies:
171
171
  - - ~>
172
172
  - !ruby/object:Gem::Version
173
173
  version: 1.7.3
174
+ - !ruby/object:Gem::Dependency
175
+ name: debugger
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ~>
180
+ - !ruby/object:Gem::Version
181
+ version: 1.5.0
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ~>
188
+ - !ruby/object:Gem::Version
189
+ version: 1.5.0
174
190
  description: ''
175
191
  email: support@getambassador.com
176
192
  executables: []
@@ -192,6 +208,7 @@ files:
192
208
  - lib/mbsy/resources/base.rb
193
209
  - lib/mbsy/resources/company.rb
194
210
  - lib/mbsy/resources/event.rb
211
+ - lib/mbsy/resources/group.rb
195
212
  - lib/mbsy/resources/shortcode.rb
196
213
  - lib/mbsy/resources/social.rb
197
214
  - mbsy.gemspec