Class: Drip::Client
- Inherits:
-
Object
show all
- Includes:
- Accounts, Campaigns, Events, Subscribers, Tags
- Defined in:
- lib/drip/client.rb,
lib/drip/client/tags.rb,
lib/drip/client/events.rb,
lib/drip/client/accounts.rb,
lib/drip/client/campaigns.rb,
lib/drip/client/subscribers.rb
Defined Under Namespace
Modules: Accounts, Campaigns, Events, Subscribers, Tags
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Campaigns
#campaigns
Methods included from Events
#track_event, #track_events
Methods included from Tags
#apply_tag, #remove_tag
#create_or_update_subscriber, #create_or_update_subscribers, #delete_subscriber, #subscribe, #subscriber, #subscribers, #unsubscribe
Methods included from Accounts
#accounts, #create_or_update_subscriber, #create_or_update_subscribers, #delete_subscriber, #subscribe, #unsubscribe
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
21
22
23
24
25
26
|
# File 'lib/drip/client.rb', line 21
def initialize(options = {})
@account_id = options[:account_id]
@access_token = options[:access_token]
@api_key = options[:api_key]
yield(self) if block_given?
end
|
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
19
20
21
|
# File 'lib/drip/client.rb', line 19
def access_token
@access_token
end
|
#account_id ⇒ Object
Returns the value of attribute account_id.
19
20
21
|
# File 'lib/drip/client.rb', line 19
def account_id
@account_id
end
|
#api_key ⇒ Object
Returns the value of attribute api_key.
19
20
21
|
# File 'lib/drip/client.rb', line 19
def api_key
@api_key
end
|
Instance Method Details
#build_response(&block) ⇒ Object
72
73
74
75
|
# File 'lib/drip/client.rb', line 72
def build_response(&block)
response = yield
Drip::Response.new(response.status, response.body)
end
|
#connection ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/drip/client.rb', line 77
def connection
@connection ||= Faraday.new do |f|
f.adapter :net_http
f.url_prefix = "https://api.getdrip.com/v2/"
f.['User-Agent'] = "Drip Ruby v#{Drip::VERSION}"
f.['Content-Type'] = content_type
f.['Accept'] = "*/*"
if access_token
f.['Authorization'] = "Bearer #{access_token}"
else
f.basic_auth api_key, ""
end
f.response :json, :content_type => /\bjson$/
end
end
|
#content_type ⇒ Object
32
33
34
|
# File 'lib/drip/client.rb', line 32
def content_type
'application/vnd.api+json'
end
|
#delete(url, options = {}) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/drip/client.rb', line 63
def delete(url, options = {})
build_response do
connection.delete do |req|
req.url url
req.body = options.to_json
end
end
end
|
#generate_resource(key, *args) ⇒ Object
28
29
30
|
# File 'lib/drip/client.rb', line 28
def generate_resource(key, *args)
{ key => args }
end
|
#get(url, options = {}) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/drip/client.rb', line 36
def get(url, options = {})
build_response do
connection.get do |req|
req.url url
req.params = options
end
end
end
|
#post(url, options = {}) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/drip/client.rb', line 45
def post(url, options = {})
build_response do
connection.post do |req|
req.url url
req.body = options.to_json
end
end
end
|
#put(url, options = {}) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/drip/client.rb', line 54
def put(url, options = {})
build_response do
connection.put do |req|
req.url url
req.body = options.to_json
end
end
end
|