Class: Drip::Client
- Inherits:
-
Object
- Object
- Drip::Client
- Includes:
- Accounts, Broadcasts, CampaignSubscriptions, Campaigns, Conversions, CustomFields, Events, Forms, Purchases, Subscribers, Tags, Webhooks, WorkflowTriggers, Workflows
- Defined in:
- lib/drip/client.rb,
lib/drip/client/tags.rb,
lib/drip/client/forms.rb,
lib/drip/client/events.rb,
lib/drip/client/accounts.rb,
lib/drip/client/webhooks.rb,
lib/drip/client/campaigns.rb,
lib/drip/client/purchases.rb,
lib/drip/client/workflows.rb,
lib/drip/client/broadcasts.rb,
lib/drip/client/conversions.rb,
lib/drip/client/subscribers.rb,
lib/drip/client/custom_fields.rb,
lib/drip/client/workflow_triggers.rb,
lib/drip/client/campaign_subscriptions.rb
Defined Under Namespace
Modules: Accounts, Broadcasts, CampaignSubscriptions, Campaigns, Conversions, CustomFields, Events, Forms, Purchases, Subscribers, Tags, Webhooks, WorkflowTriggers, Workflows
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#account_id ⇒ Object
Returns the value of attribute account_id.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
- #build_response(&block) ⇒ Object
- #connection ⇒ Object
- #content_type ⇒ Object
- #delete(url, options = {}) ⇒ Object
- #generate_resource(key, *args) ⇒ Object
- #get(url, options = {}) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #make_request(verb, url, options) ⇒ Object
- #post(url, options = {}) ⇒ Object
- #put(url, options = {}) ⇒ Object
Methods included from WorkflowTriggers
#create_workflow_trigger, #update_workflow_trigger, #workflow_triggers
Methods included from Workflows
#activate_workflow, #pause_workflow, #remove_subscriber_workflow, #start_subscriber_workflow, #workflow, #workflows
Methods included from Webhooks
#create_webhook, #delete_webhook, #webhook, #webhooks
Methods included from Tags
#apply_tag, #remove_tag, #tags
Methods included from Subscribers
#create_or_update_subscriber, #create_or_update_subscribers, #delete_subscriber, #subscribe, #subscriber, #subscribers, #unsubscribe, #unsubscribe_from_all, #unsubscribe_subscribers
Methods included from Purchases
#create_purchase, #purchase, #purchases
Methods included from Forms
Methods included from Events
#event_actions, #track_event, #track_events
Methods included from CustomFields
Methods included from Conversions
Methods included from CampaignSubscriptions
Methods included from Campaigns
#activate_campaign, #campaign, #campaign_subscribers, #campaigns, #pause_campaign
Methods included from Broadcasts
Methods included from Accounts
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
39 40 41 42 43 44 |
# File 'lib/drip/client.rb', line 39 def initialize( = {}) @account_id = [:account_id] @access_token = [:access_token] @api_key = [:api_key] yield(self) if block_given? end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
37 38 39 |
# File 'lib/drip/client.rb', line 37 def access_token @access_token end |
#account_id ⇒ Object
Returns the value of attribute account_id.
37 38 39 |
# File 'lib/drip/client.rb', line 37 def account_id @account_id end |
#api_key ⇒ Object
Returns the value of attribute api_key.
37 38 39 |
# File 'lib/drip/client.rb', line 37 def api_key @api_key end |
Instance Method Details
#build_response(&block) ⇒ Object
84 85 86 87 |
# File 'lib/drip/client.rb', line 84 def build_response(&block) response = yield Drip::Response.new(response.status, response.body) end |
#connection ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/drip/client.rb', line 89 def connection @connection ||= Faraday.new do |f| f.url_prefix = "https://api.getdrip.com/v2/" f.headers['User-Agent'] = "Drip Ruby v#{Drip::VERSION}" f.headers['Content-Type'] = content_type f.headers['Accept'] = "*/*" if access_token f.headers['Authorization'] = "Bearer #{access_token}" else f.basic_auth api_key, "" end f.response :json, content_type: /\bjson$/ f.adapter :net_http end end |
#content_type ⇒ Object
50 51 52 |
# File 'lib/drip/client.rb', line 50 def content_type 'application/vnd.api+json' end |
#delete(url, options = {}) ⇒ Object
66 67 68 |
# File 'lib/drip/client.rb', line 66 def delete(url, = {}) make_request(:delete, url, ) end |
#generate_resource(key, *args) ⇒ Object
46 47 48 |
# File 'lib/drip/client.rb', line 46 def generate_resource(key, *args) { key => args } end |
#get(url, options = {}) ⇒ Object
54 55 56 |
# File 'lib/drip/client.rb', line 54 def get(url, = {}) make_request(:get, url, ) end |
#make_request(verb, url, options) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/drip/client.rb', line 70 def make_request(verb, url, ) build_response do connection.send(verb) do |req| req.url url if verb == :get req.params = else req.body = .to_json end end end end |
#post(url, options = {}) ⇒ Object
58 59 60 |
# File 'lib/drip/client.rb', line 58 def post(url, = {}) make_request(:post, url, ) end |
#put(url, options = {}) ⇒ Object
62 63 64 |
# File 'lib/drip/client.rb', line 62 def put(url, = {}) make_request(:put, url, ) end |