linkemperor-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in linkemperor-api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Giorgenes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Linkemperor API
2
+
3
+ This library is used to access The Link Emperor API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'linkemperor-api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install linkemperor-api
18
+
19
+ ## Usage
20
+
21
+ ### Ruby
22
+
23
+ Include the gem on your project and use it like this:
24
+
25
+ require 'linkemperor-api'
26
+
27
+ # Customers
28
+ api = LinkemperorCustomer.new('<api_key>')
29
+ api.desired_method
30
+
31
+ # Vendors
32
+ api = LinkemperorVendor.new('<api_key>')
33
+ api.desired_method
34
+
35
+ ### PHP
36
+
37
+ Include the files under the 'php' directory and use it as follow:
38
+
39
+ include('customers.php');
40
+ include('vendors.php');
41
+
42
+ # Customers
43
+ $api = new LinkemperorCustomer("<api key>");
44
+ $api->some_method();
45
+
46
+ # Vendors
47
+ $api = new LinkemperorVendor("<api key>");
48
+ $api->some_method();
49
+
50
+ For details on the available operations, check documentation available on
51
+ http://www.linkemperor.com/api-documentation
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,470 @@
1
+
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+
6
+ class LinkemperorCustomer
7
+ class LinkemperorApiException < RuntimeError
8
+ end
9
+
10
+ def initialize(api_key, base_path = nil)
11
+ @base_path = base_path || 'http://app.linkemperor.com'
12
+ @api_key = api_key
13
+ end
14
+
15
+ def exec_get(uri)
16
+ uri = URI(uri)
17
+ result = Net::HTTP.get_response(uri)
18
+ if result.is_a?(Net::HTTPSuccess)
19
+ JSON.parse(result.body)
20
+ else
21
+ raise LinkemperorApiException.new result.body
22
+ end
23
+ end
24
+
25
+ def exec_post(parameters, method, uri)
26
+ uri = URI(uri)
27
+ req = case method
28
+ when 'put'
29
+ Net::HTTP::Put.new(uri.request_uri)
30
+ when 'post'
31
+ Net::HTTP::Post.new(uri.request_uri)
32
+ when 'delete'
33
+ Net::HTTP::Delete.new(uri.request_uri)
34
+ end
35
+ req.body = JSON.dump(parameters)
36
+ req.content_type = "application/json"
37
+ result = Net::HTTP.start(uri.hostname, uri.port) do |http|
38
+ http.request(req)
39
+ end
40
+ #result = Net::HTTP.post_form(uri, converted_params)
41
+ if result.is_a?(Net::HTTPSuccess)
42
+ if result.body == 'false'
43
+ false
44
+ elsif result.body == 'true'
45
+ true
46
+ else
47
+ if method != 'delete'
48
+ JSON.parse(result.body)
49
+ else
50
+ result.body
51
+ end
52
+ end
53
+ else
54
+ raise LinkemperorApiException.new result.body
55
+ end
56
+ end
57
+
58
+
59
+ # This method creates a new Article.
60
+ # Parameters:
61
+ # - campaign_id: Campaign ID for this Article
62
+ # - title: Article Title (Spintax OK)
63
+ # - body: Article Body (Spintax OK)
64
+ def create_article(campaign_id, title, body)
65
+
66
+
67
+
68
+ if campaign_id.nil?
69
+ raise LinkemperorApiException.new('campaign_id should not be empty')
70
+ end
71
+
72
+ if title.nil?
73
+ raise LinkemperorApiException.new('title should not be empty')
74
+ end
75
+
76
+ if body.nil?
77
+ raise LinkemperorApiException.new('body should not be empty')
78
+ end
79
+
80
+
81
+ parameters = {'article' => {'campaign_id' => campaign_id, 'title' => title, 'body' => body}}
82
+ exec_post(parameters, 'post', "#{@base_path}/api/v2/customers/articles.json?api_key=#{@api_key}")
83
+
84
+ end
85
+
86
+ # This method deletes the Article you specify.
87
+ # Parameters:
88
+ # - id: Article ID
89
+ def delete_article(id)
90
+
91
+
92
+
93
+ if id.nil?
94
+ raise LinkemperorApiException.new('id should not be empty')
95
+ end
96
+
97
+
98
+ parameters = {}
99
+ exec_post(parameters, 'delete', "#{@base_path}/api/v2/customers/articles/#{id}.json?api_key=#{@api_key}")
100
+
101
+ end
102
+
103
+ # This method returns a list of Articles for the Campaign.
104
+ # Parameters:
105
+ # - id: Campaign ID
106
+ def get_campaign_articles(id)
107
+
108
+
109
+
110
+ if id.nil?
111
+ raise LinkemperorApiException.new('id should not be empty')
112
+ end
113
+
114
+
115
+ exec_get("#{@base_path}/api/v2/customers/campaigns/#{id}/articles.json?api_key=#{@api_key}")
116
+
117
+ end
118
+
119
+ # This method returns a list of all the Blasts that exist on your account.
120
+ # Parameters:
121
+ # none
122
+ def get_blasts()
123
+
124
+
125
+
126
+
127
+ exec_get("#{@base_path}/api/v2/customers/blasts.json?api_key=#{@api_key}")
128
+
129
+ end
130
+
131
+ # This method returns a details about the Blast you specify
132
+ # Parameters:
133
+ # - id: Blast ID
134
+ def get_blast_by_id(id)
135
+
136
+
137
+
138
+ if id.nil?
139
+ raise LinkemperorApiException.new('id should not be empty')
140
+ end
141
+
142
+
143
+ exec_get("#{@base_path}/api/v2/customers/blasts/#{id}.json?api_key=#{@api_key}")
144
+
145
+ end
146
+
147
+ # This method returns a list of the Blasts in the Campaign.
148
+ # Parameters:
149
+ # - id: Campaign ID
150
+ def get_campaign_blasts(id)
151
+
152
+
153
+
154
+ if id.nil?
155
+ raise LinkemperorApiException.new('id should not be empty')
156
+ end
157
+
158
+
159
+ exec_get("#{@base_path}/api/v2/customers/campaigns/#{id}/blasts.json?api_key=#{@api_key}")
160
+
161
+ end
162
+
163
+ # This method creates a new campaign. Remember that if you exceed your plan limit on Campaigns, there may be additional charges.
164
+ # Parameters:
165
+ # - name: Name of the Campaign.
166
+ # - notes: Notes
167
+ def create_campaign(name, notes = nil)
168
+
169
+
170
+
171
+ if name.nil?
172
+ raise LinkemperorApiException.new('name should not be empty')
173
+ end
174
+
175
+
176
+ parameters = {'campaign' => {'name' => name, 'notes' => notes}}
177
+ exec_post(parameters, 'post', "#{@base_path}/api/v2/customers/campaigns.json?api_key=#{@api_key}")
178
+
179
+ end
180
+
181
+ # This method deletes the Campaign you specify.
182
+ # Parameters:
183
+ # - id: Campaign ID
184
+ def delete_campaign(id)
185
+
186
+
187
+
188
+ if id.nil?
189
+ raise LinkemperorApiException.new('id should not be empty')
190
+ end
191
+
192
+
193
+ parameters = {}
194
+ exec_post(parameters, 'delete', "#{@base_path}/api/v2/customers/campaigns/#{id}.json?api_key=#{@api_key}")
195
+
196
+ end
197
+
198
+ # This method returns a list of the Sites in the Campaign.
199
+ # Parameters:
200
+ # - id: Campaign ID
201
+ def get_campaign_sites(id)
202
+
203
+
204
+
205
+ if id.nil?
206
+ raise LinkemperorApiException.new('id should not be empty')
207
+ end
208
+
209
+
210
+ exec_get("#{@base_path}/api/v2/customers/campaigns/#{id}/sites.json?api_key=#{@api_key}")
211
+
212
+ end
213
+
214
+ # This method returns a list of the Targets in the Campaign.
215
+ # Parameters:
216
+ # - id: Campaign ID
217
+ def get_campaign_targets(id)
218
+
219
+
220
+
221
+ if id.nil?
222
+ raise LinkemperorApiException.new('id should not be empty')
223
+ end
224
+
225
+
226
+ exec_get("#{@base_path}/api/v2/customers/campaigns/#{id}/targets.json?api_key=#{@api_key}")
227
+
228
+ end
229
+
230
+ # This method returns a list of Trouble Spots for the Campaign.
231
+ # Parameters:
232
+ # - id: Campaign ID
233
+ def get_campaign_trouble_spots(id)
234
+
235
+
236
+
237
+ if id.nil?
238
+ raise LinkemperorApiException.new('id should not be empty')
239
+ end
240
+
241
+
242
+ exec_get("#{@base_path}/api/v2/customers/campaigns/#{id}/trouble_spots.json?api_key=#{@api_key}")
243
+
244
+ end
245
+
246
+ # This method is used to purchase link building.<br /><br />
247
+ # We call a single purchase an Order, and each order can contain multiple Blasts.<br /><br />
248
+ # First, you'll need to determine which of our link building Services you'd like to order. Use the /services endpoint of the API to get a list of available services.<br /><br />
249
+ # Now let's talk about building the actual order. An OrderRequest specifies the Services to order and the Targets (URL/anchor text) to build links to. Each Order can have multiple OrderRequests.<br /><br />
250
+ # You can see a sample OrderRequest (in JSON) by clicking "Model Schema" under the "Schema Used In Your Request" section just below.
251
+ # Parameters:
252
+ # - how_pay: How to pay for the Order. 'cash' to generate an invoice that will be settled against your account on file, or 'credits' to pull from the pool of existing credits in your account.
253
+ # - callback_url: The URL to notify when the status of the Order is updated. This occurs when component Blasts either succeed (and URLs are available for viewing) or fail (and replacement Blasts have been ordered.)
254
+ # - custom: You may provide any string here. We will save it as part of the Order and include it in the returned data whenever you check on an Order's status. It's great for holding your internal ID number for the Order.
255
+ # - requests: This is where the actual object describing your order goes. This is either a JSON nested array or XML nested tags (depending on your current format). The schema for this field is described below in the section titled Schema Used In Your Request.
256
+ def create_order(requests, how_pay = nil, callback_url = nil, custom = nil)
257
+
258
+
259
+
260
+ if requests.nil?
261
+ raise LinkemperorApiException.new('requests should not be empty')
262
+ end
263
+
264
+
265
+ parameters = {'order' => {'how_pay' => how_pay, 'callback_url' => callback_url, 'custom' => custom, 'requests' => requests}}
266
+ exec_post(parameters, 'post', "#{@base_path}/api/v2/customers/orders.json?api_key=#{@api_key}")
267
+
268
+ end
269
+
270
+ # This method shows the details of an Order and its component Blasts.<be /><be />
271
+ # It's a great way to check on an order or obtain a list of Built URLs to report back to your systems.
272
+ # Parameters:
273
+ # - id: ID # of the Order
274
+ def get_order_by_id(id)
275
+
276
+
277
+
278
+ if id.nil?
279
+ raise LinkemperorApiException.new('id should not be empty')
280
+ end
281
+
282
+
283
+ exec_get("#{@base_path}/api/v2/customers/orders/#{id}.json?api_key=#{@api_key}")
284
+
285
+ end
286
+
287
+ # If you're going to order link building, you need to check which Services are currently available.<br /><br />
288
+ # This list will change on a day-to-day or even minute-to-minute basis,
289
+ # so please look up the Services list to determine the best Services to order before placing an Order.<br /><br />
290
+ # This method returns a list of the currently available Services.
291
+ # Parameters:
292
+ # none
293
+ def get_services()
294
+
295
+
296
+
297
+
298
+ exec_get("#{@base_path}/api/v2/customers/services.json?api_key=#{@api_key}")
299
+
300
+ end
301
+
302
+ # This method returns a list of the currently available Services that
303
+ # cdon't build links on Adult or other potentially objectional sites.
304
+ # Parameters:
305
+ # none
306
+ def get_safe_services()
307
+
308
+
309
+
310
+
311
+ exec_get("#{@base_path}/api/v2/customers/services/safe.json?api_key=#{@api_key}")
312
+
313
+ end
314
+
315
+ # This method creates a new Site.
316
+ # Parameters:
317
+ # - campaign_id: Campaign ID for this Site
318
+ # - name: Name of this Site.
319
+ # - domain_name: Domain Name of this Site
320
+ # - rss_feed: RSS Feed for this Site
321
+ def create_site(campaign_id, name, domain_name, rss_feed = nil)
322
+
323
+
324
+
325
+ if campaign_id.nil?
326
+ raise LinkemperorApiException.new('campaign_id should not be empty')
327
+ end
328
+
329
+ if name.nil?
330
+ raise LinkemperorApiException.new('name should not be empty')
331
+ end
332
+
333
+ if domain_name.nil?
334
+ raise LinkemperorApiException.new('domain_name should not be empty')
335
+ end
336
+
337
+
338
+ parameters = {'site' => {'campaign_id' => campaign_id, 'name' => name, 'domain_name' => domain_name, 'rss_feed' => rss_feed}}
339
+ exec_post(parameters, 'post', "#{@base_path}/api/v2/customers/sites.json?api_key=#{@api_key}")
340
+
341
+ end
342
+
343
+ # This method deletes the Site you specify.
344
+ # Parameters:
345
+ # - id: Site ID
346
+ def delete_site(id)
347
+
348
+
349
+
350
+ if id.nil?
351
+ raise LinkemperorApiException.new('id should not be empty')
352
+ end
353
+
354
+
355
+ parameters = {}
356
+ exec_post(parameters, 'delete', "#{@base_path}/api/v2/customers/sites/#{id}.json?api_key=#{@api_key}")
357
+
358
+ end
359
+
360
+ # This method creates a new Target. You will need to provide a Campaign ID and a URL for the target.
361
+ # Parameters:
362
+ # - campaign_id: Campaign ID
363
+ # - url_input: Fully qualified URL for the target.
364
+ # - keyword_input: Keywords to add to the target. Separate multiple keywords with linebreaks.
365
+ def create_target(campaign_id, url_input, keyword_input = nil)
366
+
367
+
368
+
369
+ if campaign_id.nil?
370
+ raise LinkemperorApiException.new('campaign_id should not be empty')
371
+ end
372
+
373
+ if url_input.nil?
374
+ raise LinkemperorApiException.new('url_input should not be empty')
375
+ end
376
+
377
+
378
+ parameters = {'target' => {'campaign_id' => campaign_id, 'url_input' => url_input, 'keyword_input' => keyword_input}}
379
+ exec_post(parameters, 'post', "#{@base_path}/api/v2/customers/targets.json?api_key=#{@api_key}")
380
+
381
+ end
382
+
383
+ # This method deletes the Target you specify.
384
+ # Parameters:
385
+ # - id: Target ID
386
+ def delete_target(id)
387
+
388
+
389
+
390
+ if id.nil?
391
+ raise LinkemperorApiException.new('id should not be empty')
392
+ end
393
+
394
+
395
+ parameters = {}
396
+ exec_post(parameters, 'delete', "#{@base_path}/api/v2/customers/targets/#{id}.json?api_key=#{@api_key}")
397
+
398
+ end
399
+
400
+ # This method creates a new Keyword. You will need to provide a Target ID.
401
+ # Parameters:
402
+ # - target_id: Target ID
403
+ # - keyword_string: Keyword string
404
+ def create_target_keyword(target_id, keyword_string)
405
+
406
+
407
+
408
+ if target_id.nil?
409
+ raise LinkemperorApiException.new('target_id should not be empty')
410
+ end
411
+
412
+ if keyword_string.nil?
413
+ raise LinkemperorApiException.new('keyword_string should not be empty')
414
+ end
415
+
416
+
417
+ parameters = {'target_keyword' => {'target_id' => target_id, 'keyword_string' => keyword_string}}
418
+ exec_post(parameters, 'post', "#{@base_path}/api/v2/customers/target_keywords.json?api_key=#{@api_key}")
419
+
420
+ end
421
+
422
+ # This method deletes the Keyword you specify.
423
+ # Parameters:
424
+ # - id: Keyword ID
425
+ def delete_target_keyword(id)
426
+
427
+
428
+
429
+ if id.nil?
430
+ raise LinkemperorApiException.new('id should not be empty')
431
+ end
432
+
433
+
434
+ parameters = {}
435
+ exec_post(parameters, 'delete', "#{@base_path}/api/v2/customers/target_keywords/#{id}.json?api_key=#{@api_key}")
436
+
437
+ end
438
+
439
+ # This method returns a list of all the Trouble Spots that exist on your account.
440
+ #
441
+ # Trouble Spots are issues spotted by our On-Page SEO Checker for Campaigns.
442
+ # Parameters:
443
+ # none
444
+ def get_trouble_spots()
445
+
446
+
447
+
448
+
449
+ exec_get("#{@base_path}/api/v2/customers/trouble_spots.json?api_key=#{@api_key}")
450
+
451
+ end
452
+
453
+ # This method returns details about the Trouble Spot you specify.
454
+ # Parameters:
455
+ # - id: TroubleSpot ID
456
+ def get_trouble_spot_by_id(id)
457
+
458
+
459
+
460
+ if id.nil?
461
+ raise LinkemperorApiException.new('id should not be empty')
462
+ end
463
+
464
+
465
+ exec_get("#{@base_path}/api/v2/customers/trouble_spots/#{id}.json?api_key=#{@api_key}")
466
+
467
+ end
468
+
469
+ end
470
+