aweber 1.4.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- h1. AWeber API Gem "!https://secure.travis-ci.org/aweber/AWeber-API-Ruby-Library.png!":http://travis-ci.org/aweber/AWeber-API-Ruby-Library
1
+ h1. AWeber API Gem "!https://secure.travis-ci.org/aweber/AWeber-API-Ruby-Library.png?branch=master!":http://travis-ci.org/aweber/AWeber-API-Ruby-Library
2
2
 
3
3
  Official AWeber API gem.
4
4
 
@@ -10,7 +10,7 @@ h2. Getting Started
10
10
 
11
11
  This guide assumes you have nothing previously setup to work with the AWeber API. It will walk through registering an account, creating an app and everything up to the point where you'll actually start working with data.
12
12
 
13
- If you don't want to bother with all the account setup stuff, you can look in the "examples":http://github.com/aweber/aweber-ruby/tree/master/examples/ directory for just example code.
13
+ If you don't want to bother with all the account setup stuff, you can look in the "examples":https://github.com/aweber/AWeber-API-Ruby-Library/tree/master/examples directory for just example code.
14
14
 
15
15
  *Requires a normal AWeber account (not a Labs account)*
16
16
 
@@ -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.3"
4
+ s.version = "1.5.0"
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"
@@ -61,6 +61,7 @@ module AWeber
61
61
  class UnknownRequestError < Exception; end
62
62
  class RateLimitError < Exception; end
63
63
  class ForbiddenRequestError < Exception; end
64
+ class CreationError < Exception; end
64
65
  end
65
66
 
66
67
  $LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
@@ -51,6 +51,11 @@ module AWeber
51
51
  end
52
52
 
53
53
  def search(params={})
54
+ if params.has_key?('custom_fields')
55
+ if params['custom_fields'].is_a?(Hash)
56
+ params['custom_fields'] = params['custom_fields'].to_json
57
+ end
58
+ end
54
59
  params = params.map { |k,v| "#{h(k)}=#{h(v)}" }.join("&")
55
60
  uri = "#{path}?ws.op=find&#{params}"
56
61
  response = client.get(uri).merge(:parent => parent)
@@ -58,7 +63,7 @@ module AWeber
58
63
 
59
64
  self.class.new(client, @klass, response)
60
65
  end
61
-
66
+
62
67
  def create(attrs={})
63
68
  params = attrs.merge("ws.op" => "create")
64
69
 
@@ -70,18 +75,24 @@ module AWeber
70
75
 
71
76
  response = client.post(path, params)
72
77
 
73
- return false unless response.is_a? Net::HTTPCreated
78
+ if response.is_a? Net::HTTPCreated
79
+ resource = get(response["location"]).merge(:parent => self)
80
+ resource = @klass.new(client, resource)
74
81
 
75
- resource = get(response["location"]).merge(:parent => self)
76
- resource = @klass.new(client, resource)
77
-
78
- self[resource.id] = resource
82
+ self[resource.id] = resource
83
+ else
84
+ if response
85
+ raise CreationError, JSON.parse(response.body)['error']['message'], caller
86
+ else
87
+ raise CreationError, "No response received", caller
88
+ end
89
+ end
79
90
  end
80
91
 
81
92
  def [](id)
82
93
  @entries[id] ||= fetch_entry(id)
83
94
  end
84
-
95
+
85
96
  def []=(key, resource)
86
97
  @entries[key] = resource
87
98
  end
@@ -93,7 +104,7 @@ module AWeber
93
104
  def inspect
94
105
  "#<AW::Collection(#{@klass.to_s}) size=\"#{size}\">"
95
106
  end
96
-
107
+
97
108
  def path
98
109
  parent and parent.path.to_s + @klass.path.to_s or @klass.path.to_s
99
110
  end
@@ -140,7 +151,7 @@ module AWeber
140
151
  end
141
152
  super
142
153
  end
143
-
154
+
144
155
  def client
145
156
  @client
146
157
  end
@@ -80,30 +80,31 @@ describe AWeber::Collection do
80
80
  end
81
81
 
82
82
  describe "when creating" do
83
- let(:params) {{ "ws.op" => "create", :name => "foo" }}
83
+ let(:params) {{ "ws.op" => "create", "name" => "foo" }}
84
84
 
85
85
  it "should set the operation to 'create'" do
86
86
  @aweber.should_receive(:post).with(@lists.path, params)
87
- @lists.create(:name => "foo")
87
+ expect { @lists.create("name" => "foo")}.to raise_error
88
+
88
89
  end
89
90
 
90
- it "should return false if the create failed" do
91
+ it "should return raise CreationError if the create failed" do
91
92
  @oauth.should_receive(:post).and_return(nil)
92
- @lists.create(:name => "foo").should == false
93
+ expect {@lists.create("name" => "foo")}.to raise_error
93
94
  end
94
95
 
95
96
  it "should return the new object if the create succeeded" do
96
- @lists.create(:name => "foo").should be_an AWeber::Resource
97
+ @lists.create("name" => "foo").should be_an AWeber::Resource
97
98
  end
98
99
 
99
100
  it "should have the collection as a parent" do
100
- @lists.create(:name => "foo").parent.should == @lists
101
+ @lists.create("name" => "foo").parent.should == @lists
101
102
  end
102
103
 
103
104
  it "should set operation to create when creating subscriber" do
104
- expected = { "ws.op" => "create", :name => "foo", :custom_fields => {"Signature" => '1234'} }
105
+ expected = { "ws.op" => "create", "name" => "foo", :custom_fields => {"Signature" => '1234'} }
105
106
  @aweber.should_receive(:post).with(@subscribers.path, expected)
106
- @subscribers.create(:name => "foo", :custom_fields => {"Signature" => '1234'})
107
+ expect {@subscribers.create("name" => "foo", :custom_fields => {"Signature" => '1234'})}.to raise_error
107
108
  end
108
109
 
109
110
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 4
8
- - 3
9
- version: 1.4.3
7
+ - 5
8
+ - 0
9
+ version: 1.5.0
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-23 00:00:00 -04:00
17
+ date: 2012-10-09 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency