Class: Drip::Client

Inherits:
Object
  • Object
show all
Includes:
Accounts, Broadcasts, CampaignSubscriptions, Campaigns, Conversions, CustomFields, Events, Forms, Orders, 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/orders.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, Orders, Purchases, Subscribers, Tags, Webhooks, WorkflowTriggers, Workflows

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Methods included from Orders

#create_or_update_order, #create_or_update_orders, #create_or_update_refund

Methods included from Forms

#form, #forms

Methods included from Events

#event_actions, #track_event, #track_events

Methods included from CustomFields

#custom_fields

Methods included from Conversions

#conversion, #conversions

Methods included from CampaignSubscriptions

#campaign_subscriptions

Methods included from Campaigns

#activate_campaign, #campaign, #campaign_subscribers, #campaigns, #pause_campaign

Methods included from Broadcasts

#broadcast, #broadcasts

Methods included from Accounts

#account, #accounts

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:

  • _self (Drip::Client)

    the object that the method was called on



41
42
43
44
45
46
# File 'lib/drip/client.rb', line 41

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_tokenObject

Returns the value of attribute access_token.



39
40
41
# File 'lib/drip/client.rb', line 39

def access_token
  @access_token
end

#account_idObject

Returns the value of attribute account_id.



39
40
41
# File 'lib/drip/client.rb', line 39

def 
  @account_id
end

#api_keyObject

Returns the value of attribute api_key.



39
40
41
# File 'lib/drip/client.rb', line 39

def api_key
  @api_key
end

Instance Method Details

#build_response(&block) ⇒ Object



86
87
88
89
# File 'lib/drip/client.rb', line 86

def build_response(&block)
  response = yield
  Drip::Response.new(response.status, response.body)
end

#connectionObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/drip/client.rb', line 91

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_typeObject



52
53
54
# File 'lib/drip/client.rb', line 52

def content_type
  'application/vnd.api+json'
end

#delete(url, options = {}) ⇒ Object



68
69
70
# File 'lib/drip/client.rb', line 68

def delete(url, options = {})
  make_request(:delete, url, options)
end

#generate_resource(key, *args) ⇒ Object



48
49
50
# File 'lib/drip/client.rb', line 48

def generate_resource(key, *args)
  { key => args }
end

#get(url, options = {}) ⇒ Object



56
57
58
# File 'lib/drip/client.rb', line 56

def get(url, options = {})
  make_request(:get, url, options)
end

#make_request(verb, url, options) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/drip/client.rb', line 72

def make_request(verb, url, options)
  build_response do
    connection.send(verb) do |req|
      req.url url

      if verb == :get
        req.params = options
      else
        req.body = options.to_json
      end
    end
  end
end

#post(url, options = {}) ⇒ Object



60
61
62
# File 'lib/drip/client.rb', line 60

def post(url, options = {})
  make_request(:post, url, options)
end

#put(url, options = {}) ⇒ Object



64
65
66
# File 'lib/drip/client.rb', line 64

def put(url, options = {})
  make_request(:put, url, options)
end