aweber 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "aweber"
4
- s.version = "1.4.2"
4
+ s.version = "1.4.3"
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.summary = "Ruby interface to AWeber's API"
7
7
  s.description = "Ruby interface to AWeber's API"
@@ -1,6 +1,6 @@
1
1
  require "forwardable"
2
2
  require "oauth"
3
- require "json/pure"
3
+ require "json"
4
4
 
5
5
  module AWeber
6
6
  API_VERSION = "1.0".freeze
@@ -59,6 +59,8 @@ module AWeber
59
59
  class OAuthError < Exception; end
60
60
  class NotFoundError < Exception; end
61
61
  class UnknownRequestError < Exception; end
62
+ class RateLimitError < Exception; end
63
+ class ForbiddenRequestError < Exception; end
62
64
  end
63
65
 
64
66
  $LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
@@ -42,6 +42,12 @@ module AWeber
42
42
  raise NotFoundError, "Invalid resource uri.", caller
43
43
  elsif response && response.body == "NotAuthorizedError"
44
44
  raise OAuthError, "Could not authorize OAuth credentials.", caller
45
+ elsif response.is_a? Net::HTTPForbidden
46
+ if JSON.parse(response.body)['error']['message'].start_with?("Rate limit")
47
+ raise RateLimitError, "Too many API requests per minute.", caller
48
+ elsif JSON.parse(response.body)['error']['message'].start_with?("Method requires access")
49
+ raise ForbiddenRequestError, "Method requires extended permissions.", caller
50
+ end
45
51
  end
46
52
  end
47
53
 
@@ -70,4 +76,4 @@ module AWeber
70
76
  @oauth
71
77
  end
72
78
  end
73
- end
79
+ end
@@ -60,7 +60,14 @@ module AWeber
60
60
  end
61
61
 
62
62
  def create(attrs={})
63
- params = attrs.merge("ws.op" => "create")
63
+ params = attrs.merge("ws.op" => "create")
64
+
65
+ if params.has_key?('custom_fields')
66
+ if params['custom_fields'].is_a?(Hash)
67
+ params['custom_fields'] = params['custom_fields'].to_json
68
+ end
69
+ end
70
+
64
71
  response = client.post(path, params)
65
72
 
66
73
  return false unless response.is_a? Net::HTTPCreated
@@ -5,7 +5,9 @@ describe AWeber::Collection do
5
5
  @oauth = AWeber::OAuth.new("token", "secret")
6
6
  @aweber = AWeber::Base.new(@oauth)
7
7
  data = JSON.parse(fixture("lists.json")).merge(:parent => @aweber.account)
8
+ sub_data = JSON.parse(fixture("subscriber.json")).merge(:parent => @aweber.account)
8
9
  @lists = AWeber::Collection.new(@aweber, AWeber::Resources::List, data)
10
+ @subscribers = AWeber::Collection.new(@aweber, AWeber::Resources::Subscriber, data)
9
11
  end
10
12
 
11
13
  it "should create classes from the one passed into initialize" do
@@ -97,6 +99,13 @@ describe AWeber::Collection do
97
99
  it "should have the collection as a parent" do
98
100
  @lists.create(:name => "foo").parent.should == @lists
99
101
  end
102
+
103
+ it "should set operation to create when creating subscriber" do
104
+ expected = { "ws.op" => "create", :name => "foo", :custom_fields => {"Signature" => '1234'} }
105
+ @aweber.should_receive(:post).with(@subscribers.path, expected)
106
+ @subscribers.create(:name => "foo", :custom_fields => {"Signature" => '1234'})
107
+ end
108
+
100
109
  end
101
110
 
102
111
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 4
8
- - 2
9
- version: 1.4.2
8
+ - 3
9
+ version: 1.4.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - AWeber Communications, Inc.
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-08-16 00:00:00 -04:00
17
+ date: 2012-08-23 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency