This repository has been archived by the owner on Aug 29, 2019. It is now read-only.
forked from cgilchrist/AWeber-API-Ruby-Library
-
Notifications
You must be signed in to change notification settings - Fork 18
/
aweber.rb
72 lines (62 loc) · 1.92 KB
/
aweber.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require "forwardable"
require "oauth"
require "json"
module AWeber
API_VERSION = "1.0".freeze
AUTH_VERSION = "1.0".freeze
# Used for +has_many+ and +has_one+ relationships.
#
INFLECTIONS = {
:accounts => :Account,
:clicks => :Click,
:links => :Link,
:lists => :List,
:custom_fields => :CustomField,
:campaigns => :Campaign,
:messages => :Message,
:opens => :Open,
:subscribers => :Subscriber,
:tracked_events => :TrackedEvent,
:integrations => :Integration,
:web_forms => :WebForm,
:components => :WebFormSplitTestComponent,
:web_form_split_tests => :WebFormSplitTest,
:last_followup_sents => :Followup
}
class << self
# @param [String] Base URL of the API server
#
attr_accessor :api_endpoint
# @param [String] Base URL of the Auth server
#
attr_accessor :auth_endpoint
def api_url
File.join api_endpoint, API_VERSION
end
def auth_url
File.join auth_endpoint, AUTH_VERSION
end
# Retrieves the Resource class based on the
# +INFLECTIONS+ map and +name+.
#
# @param [Symbol] name Collection name
#
def get_class(name)
Resources.const_get(INFLECTIONS[name])
end
end
@api_endpoint = "https://api.aweber.com"
@auth_endpoint = "https://auth.aweber.com"
class OAuthError < Exception; end
class NotFoundError < Exception; end
class UnknownRequestError < Exception; end
class RateLimitError < Exception; end
class ForbiddenRequestError < Exception; end
class CreationError < Exception; end
end
$LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
require "aweber/oauth"
require "aweber/base"
require "aweber/resource"
require "aweber/resources"
require "aweber/collection"