active-campaign-rails 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1e5e7a01a49e887744994ec3b462221930689e7
4
- data.tar.gz: 69f93abd48b2faa52f3fb6f65d17bbee133c1830
3
+ metadata.gz: 810d05b08286eefe61eacc0cd7612aaa24dcbf48
4
+ data.tar.gz: 0f8bc286e1be43773bd01164d3e32620692d96ee
5
5
  SHA512:
6
- metadata.gz: 5d3620beb5e7631f47ceccbc099af3cbf37448be2b64dfca6dd11ffd0fdc156961e867959777ba900094f5014f3b97c873b877d32d60e6a03d588350d85b3c07
7
- data.tar.gz: 0945349e98e61dd532020df98ec59ce699d575cc2cfacebfe645ef952cc49667d79f53c0fb848fcdeddecd4fa33ba8f5ada86404b148491393ea74693cb9eb78
6
+ metadata.gz: 22dcf53d53ac8f35398b90de04d839ec3d4d5151bff23a51fc0ea8cf87efb00e9eb45bdf89ec8307b724d537dd1f4daa4f2d8f6a3d858eb3bcec6a1da06bd2c7
7
+ data.tar.gz: 0ebb0d76d41aaa066a628f9abf38203a0a5d3e625d5ca7f7d9bb70db2fbf390ea90574a1edd677cdd21cf4650a5e792f524bef59eaa5ae93b1d507930d6489fa
@@ -1,7 +1,11 @@
1
1
  require "active-campaign-rails/version"
2
+ require "active-campaign-rails/client"
2
3
 
3
4
  class ActiveCampaign
4
-
5
+
6
+ # Makes the Client's methods available to an instance of the ActiveCampaign class
7
+ include Client
8
+
5
9
  attr_reader :api_endpoint, :api_key
6
10
 
7
11
  def initialize args
@@ -11,8 +15,8 @@ class ActiveCampaign
11
15
  instance_variable_set("@#{k}", v) unless v.nil?
12
16
  end
13
17
 
14
- # Set default api_output to json
15
- @api_output = 'json'
18
+ # Set default api_output to json if not set
19
+ @api_output = 'json' if @api_output.blank?
16
20
 
17
21
  end
18
22
 
@@ -23,186 +27,36 @@ class ActiveCampaign
23
27
  api_url = "#{@api_endpoint}/admin/api.php?api_key=#{@api_key}&api_action=#{api_action.to_s}&api_output=#{@api_output}"
24
28
 
25
29
  # Check method for api_action given
26
- case client[api_action][:method]
30
+ case action_calls[api_action][:method]
27
31
  when 'get'
28
32
 
29
- url_params = (args.present?) ? args.first.map{|k,v| "#{k}=#{v}"}.join('su&') : nil
30
- api_url = (url_params.present?) ? "#{api_url}&#{url_params}" : api_url
33
+ # Generate API parameter from given argument
34
+ api_params = (args.present?) ? args.first.map{|k,v| "#{k}=#{v}"}.join('su&') : nil
35
+
36
+ # Join API url and API parameters
37
+ api_url = (api_params.present?) ? "#{api_url}&#{api_params}" : api_url
38
+
39
+ # Make a call to API server with GET method
31
40
  response = Net::HTTP.get(URI.parse("#{api_url}"))
32
41
 
42
+ # Return response from API server
43
+ # Default to JSON
33
44
  return response
34
45
 
35
46
  when 'post'
36
47
 
37
- response = Net::HTTP.post_form(URI.parse("#{api_url}"), args.first)
48
+ # API parameters for POST method
49
+ api_params = args.first
38
50
 
51
+ # Make a call to API server with POST method
52
+ response = Net::HTTP.post_form(URI.parse("#{api_url}"), api_params)
53
+
54
+ # Return response from API server
55
+ # Default to JSON
39
56
  return response.body
40
57
 
41
58
  end
42
-
43
-
44
- end
45
59
 
46
- # List for all Active Campaign API and their method
47
- # For more information visit http://www.activecampaign.com/api/overview.php
48
- # TODO: Refactor this!
49
- def client
50
-
51
- api_list = {
52
- # Account View
53
- account_view: { method: 'get' },
54
-
55
- # Automation
56
- automation_contact_add: { method: 'post' },
57
- automation_contact_list: { method: 'get' },
58
- automation_contact_remove: { method: 'post' },
59
- automation_contact_view: { method: 'get' },
60
- automation_list: { method: 'get' },
61
-
62
- # Branding
63
- branding_edit: { method: 'post' },
64
- branding_view: { method: 'get' },
65
-
66
- # Campaign
67
- campaign_create: { method: 'post' },
68
- campaign_delete: { method: 'post' },
69
- campaign_delete_list: { method: 'post' },
70
- campaign_list: { method: 'get' },
71
- campaign_paginator: { method: 'get' },
72
- campaign_report_bounce_list: { method: 'get' },
73
- campaign_report_bounce_totals: { method: 'get' },
74
- campaign_report_forward_list: { method: 'get' },
75
- campaign_report_forward_totals: { method: 'get' },
76
- campaign_report_link_list: { method: 'get' },
77
- campaign_report_link_totals: { method: 'get' },
78
- campaign_report_open_list: { method: 'get' },
79
- campaign_report_open_totals: { method: 'get' },
80
- campaign_report_totals: { method: 'get' },
81
- campaign_report_unopen_list: { method: 'get' },
82
- campaign_report_unsubscription_list: { method: 'get' },
83
- campaign_report_unsubscription_totals: { method: 'get' },
84
- campaign_send: { method: 'post' },
85
- campaign_status: { method: 'get' },
86
-
87
- # Contact
88
- contact_add: { method: 'post' },
89
- contact_automation_list: { method: 'get' },
90
- contact_delete: { method: 'post' },
91
- contact_delete_list: { method: 'post' },
92
- contact_edit: { method: 'post' },
93
- contact_list: { method: 'get' },
94
- contact_note_add: { method: 'post' },
95
- contact_note_delete: { method: 'post' },
96
- contact_note_edit: { method: 'post' },
97
- contact_paginator: { method: 'get' },
98
- contact_sync: { method: 'post' },
99
- contact_tag_add: { method: 'post' },
100
- contact_tag_remove: { method: 'post' },
101
- contact_view: { method: 'get' },
102
- contact_view_email: { method: 'get' },
103
- contact_view_hash: { method: 'get' },
104
-
105
- # Deal
106
- deal_add: { method: 'post' },
107
- deal_delete: { method: 'post' },
108
- deal_edit: { method: 'post' },
109
- deal_get: { method: 'get' },
110
- deal_list: { method: 'get' },
111
- deal_note_add: { method: 'post' },
112
- deal_note_edit: { method: 'post' },
113
- deal_pipeline_add: { method: 'post' },
114
- deal_pipeline_delete: { method: 'post' },
115
- deal_pipeline_edit: { method: 'post' },
116
- deal_pipeline_list: { method: 'get' },
117
- deal_stage_add: { method: 'post' },
118
- deal_stage_delete: { method: 'post' },
119
- deal_stage_edit: { method: 'post' },
120
- deal_stage_list: { method: 'get' },
121
- deal_task_add: { method: 'post' },
122
- deal_task_edit: { method: 'post' },
123
- deal_tasktype_add: { method: 'post' },
124
- deal_tasktype_delete: { method: 'post' },
125
- deal_tasktype_edit: { method: 'post' },
126
-
127
- # Form
128
- # form_getforms: { method: 'get' },
129
- # form_html: { method: 'get' },
130
-
131
- # Group
132
- group_add: { method: 'post' },
133
- group_delete: { method: 'post' },
134
- group_delete_list: { method: 'post' },
135
- group_edit: { method: 'post' },
136
- group_list: { method: 'get' },
137
- group_view: { method: 'get' },
138
-
139
- # List
140
- list_add: { method: 'post' },
141
- list_delete: { method: 'post' },
142
- list_delete_list: { method: 'post' },
143
- list_edit: { method: 'post' },
144
- list_field_add: { method: 'post' },
145
- list_field_delete: { method: 'post' },
146
- list_field_edit: { method: 'post' },
147
- list_field_view: { method: 'get' },
148
- list_list: { method: 'get' },
149
- list_paginator: { method: 'get' },
150
- list_view: { method: 'get' },
151
-
152
- # Message
153
- message_add: { method: 'post' },
154
- message_delete: { method: 'post' },
155
- message_delete_list: { method: 'post' },
156
- message_edit: { method: 'post' },
157
- message_list: { method: 'get' },
158
- message_template_add: { method: 'post' },
159
- message_template_delete: { method: 'post' },
160
- message_template_delete_list: { method: 'post' },
161
- message_template_edit: { method: 'post' },
162
- message_template_export: { method: 'get' },
163
- message_template_import: { method: 'get' },
164
- message_template_list: { method: 'get' },
165
- message_template_view: { method: 'get' },
166
- message_view: { method: 'get' },
167
-
168
- # Organization
169
- organization_list: { method: 'get' },
170
-
171
- # Settings
172
- settings_edit: { method: 'post' },
173
-
174
- # Single Sign On
175
- # singlesignon: { method: 'get' },
176
-
177
- # Site & Event Tracking
178
- track_event_delete: { method: 'post' },
179
- track_event_list: { method: 'get' },
180
- track_event_status_edit: { method: 'post' },
181
- track_site_list: { method: 'get' },
182
- track_site_status_edit: { method: 'post' },
183
- track_site_whitelist_add: { method: 'post' },
184
- track_site_whitelist_delete: { method: 'post' },
185
- track_event_add: { method: 'post' },
186
-
187
- # User
188
- user_add: { method: 'post' },
189
- user_delete: { method: 'post' },
190
- user_delete_list: { method: 'post' },
191
- user_edit: { method: 'post' },
192
- user_list: { method: 'get' },
193
- user_me: { method: 'get' },
194
- user_view: { method: 'get' },
195
- user_view_email: { method: 'get' },
196
- user_view_username: { method: 'get' },
197
-
198
- # Webhook
199
- webhook_add: { method: 'post' },
200
- webhook_delete: { method: 'post' },
201
- webhook_edit: { method: 'post' },
202
- webhook_events: { method: 'get' },
203
- webhook_list: { method: 'get' },
204
- webhook_view: { method: 'get' }
205
- }
206
60
  end
207
61
 
208
62
  end
@@ -0,0 +1,164 @@
1
+ module Client
2
+ # List for all Active Campaign API and their method
3
+ # For more information visit http://www.activecampaign.com/api/overview.php
4
+ # TODO: Refactor this!
5
+ # Need best practice to grouping APIs
6
+ def action_calls
7
+ api_list = {
8
+ # Account View
9
+ account_view: { method: 'get' },
10
+
11
+ # Automation
12
+ automation_contact_add: { method: 'post' },
13
+ automation_contact_list: { method: 'get' },
14
+ automation_contact_remove: { method: 'post' },
15
+ automation_contact_view: { method: 'get' },
16
+ automation_list: { method: 'get' },
17
+
18
+ # Branding
19
+ branding_edit: { method: 'post' },
20
+ branding_view: { method: 'get' },
21
+
22
+ # Campaign
23
+ campaign_create: { method: 'post' },
24
+ campaign_delete: { method: 'post' },
25
+ campaign_delete_list: { method: 'post' },
26
+ campaign_list: { method: 'get' },
27
+ campaign_paginator: { method: 'get' },
28
+ campaign_report_bounce_list: { method: 'get' },
29
+ campaign_report_bounce_totals: { method: 'get' },
30
+ campaign_report_forward_list: { method: 'get' },
31
+ campaign_report_forward_totals: { method: 'get' },
32
+ campaign_report_link_list: { method: 'get' },
33
+ campaign_report_link_totals: { method: 'get' },
34
+ campaign_report_open_list: { method: 'get' },
35
+ campaign_report_open_totals: { method: 'get' },
36
+ campaign_report_totals: { method: 'get' },
37
+ campaign_report_unopen_list: { method: 'get' },
38
+ campaign_report_unsubscription_list: { method: 'get' },
39
+ campaign_report_unsubscription_totals: { method: 'get' },
40
+ campaign_send: { method: 'post' },
41
+ campaign_status: { method: 'get' },
42
+
43
+ # Contact
44
+ contact_add: { method: 'post' },
45
+ contact_automation_list: { method: 'get' },
46
+ contact_delete: { method: 'post' },
47
+ contact_delete_list: { method: 'post' },
48
+ contact_edit: { method: 'post' },
49
+ contact_list: { method: 'get' },
50
+ contact_note_add: { method: 'post' },
51
+ contact_note_delete: { method: 'post' },
52
+ contact_note_edit: { method: 'post' },
53
+ contact_paginator: { method: 'get' },
54
+ contact_sync: { method: 'post' },
55
+ contact_tag_add: { method: 'post' },
56
+ contact_tag_remove: { method: 'post' },
57
+ contact_view: { method: 'get' },
58
+ contact_view_email: { method: 'get' },
59
+ contact_view_hash: { method: 'get' },
60
+
61
+ # Deal
62
+ deal_add: { method: 'post' },
63
+ deal_delete: { method: 'post' },
64
+ deal_edit: { method: 'post' },
65
+ deal_get: { method: 'get' },
66
+ deal_list: { method: 'get' },
67
+ deal_note_add: { method: 'post' },
68
+ deal_note_edit: { method: 'post' },
69
+ deal_pipeline_add: { method: 'post' },
70
+ deal_pipeline_delete: { method: 'post' },
71
+ deal_pipeline_edit: { method: 'post' },
72
+ deal_pipeline_list: { method: 'get' },
73
+ deal_stage_add: { method: 'post' },
74
+ deal_stage_delete: { method: 'post' },
75
+ deal_stage_edit: { method: 'post' },
76
+ deal_stage_list: { method: 'get' },
77
+ deal_task_add: { method: 'post' },
78
+ deal_task_edit: { method: 'post' },
79
+ deal_tasktype_add: { method: 'post' },
80
+ deal_tasktype_delete: { method: 'post' },
81
+ deal_tasktype_edit: { method: 'post' },
82
+
83
+ # Form
84
+ # form_getforms: { method: 'get' },
85
+ # form_html: { method: 'get' },
86
+
87
+ # Group
88
+ group_add: { method: 'post' },
89
+ group_delete: { method: 'post' },
90
+ group_delete_list: { method: 'post' },
91
+ group_edit: { method: 'post' },
92
+ group_list: { method: 'get' },
93
+ group_view: { method: 'get' },
94
+
95
+ # List
96
+ list_add: { method: 'post' },
97
+ list_delete: { method: 'post' },
98
+ list_delete_list: { method: 'post' },
99
+ list_edit: { method: 'post' },
100
+ list_field_add: { method: 'post' },
101
+ list_field_delete: { method: 'post' },
102
+ list_field_edit: { method: 'post' },
103
+ list_field_view: { method: 'get' },
104
+ list_list: { method: 'get' },
105
+ list_paginator: { method: 'get' },
106
+ list_view: { method: 'get' },
107
+
108
+ # Message
109
+ message_add: { method: 'post' },
110
+ message_delete: { method: 'post' },
111
+ message_delete_list: { method: 'post' },
112
+ message_edit: { method: 'post' },
113
+ message_list: { method: 'get' },
114
+ message_template_add: { method: 'post' },
115
+ message_template_delete: { method: 'post' },
116
+ message_template_delete_list: { method: 'post' },
117
+ message_template_edit: { method: 'post' },
118
+ message_template_export: { method: 'get' },
119
+ message_template_import: { method: 'get' },
120
+ message_template_list: { method: 'get' },
121
+ message_template_view: { method: 'get' },
122
+ message_view: { method: 'get' },
123
+
124
+ # Organization
125
+ organization_list: { method: 'get' },
126
+
127
+ # Settings
128
+ settings_edit: { method: 'post' },
129
+
130
+ # Single Sign On
131
+ # singlesignon: { method: 'get' },
132
+
133
+ # Site & Event Tracking
134
+ track_event_delete: { method: 'post' },
135
+ track_event_list: { method: 'get' },
136
+ track_event_status_edit: { method: 'post' },
137
+ track_site_list: { method: 'get' },
138
+ track_site_status_edit: { method: 'post' },
139
+ track_site_whitelist_add: { method: 'post' },
140
+ track_site_whitelist_delete: { method: 'post' },
141
+ track_event_add: { method: 'post' },
142
+
143
+ # User
144
+ user_add: { method: 'post' },
145
+ user_delete: { method: 'post' },
146
+ user_delete_list: { method: 'post' },
147
+ user_edit: { method: 'post' },
148
+ user_list: { method: 'get' },
149
+ user_me: { method: 'get' },
150
+ user_view: { method: 'get' },
151
+ user_view_email: { method: 'get' },
152
+ user_view_username: { method: 'get' },
153
+
154
+ # Webhook
155
+ webhook_add: { method: 'post' },
156
+ webhook_delete: { method: 'post' },
157
+ webhook_edit: { method: 'post' },
158
+ webhook_events: { method: 'get' },
159
+ webhook_list: { method: 'get' },
160
+ webhook_view: { method: 'get' }
161
+ }
162
+ end
163
+
164
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveCampaignRails
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-campaign-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eky Fauzi
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - active-campaign-rails.gemspec
54
54
  - lib/active-campaign-rails.rb
55
+ - lib/active-campaign-rails/client.rb
55
56
  - lib/active-campaign-rails/version.rb
56
57
  homepage: ''
57
58
  licenses: