class Adfly::API
Unofficial API
Wrapper for adf.ly
Constants
- URL_API
Unique url
API
Public Class Methods
new(uid, key)
click to toggle source
Create instance to use API
adfly
If you want to get API
key from adf.ly/publisher/tools#tools-api
@param uid [String] Uid @param key [String] Key
# File lib/adfly/adfly.rb, line 17 def initialize uid, key @uid, @key = uid, key end
Public Instance Methods
create_link(data)
click to toggle source
Create single link
Maybe you want to see adf.ly/publisher/tools#tools-api
@param data [Hash] data to send api
@option data [String] :url Link to be converted @option data [Symbol] :advert_type Type of advertisement(:int or :banner) @option data [String] :domain Alias domain to be used for ther generated link
@example Simple use
adfly.create_link(url: 'http://www.google.es')
@return [String] Short link
@raise [ArgumentError] Invalid parameters, link cannot be created
# File lib/adfly/adfly.rb, line 37 def create_link data body = http_get URL_API, {key: @key, uid: @uid}.merge(data) raise ArgumentError if body.nil? || body.empty? body end
Private Instance Methods
http_get(url, data)
click to toggle source
# File lib/adfly/adfly.rb, line 45 def http_get url, data uri = URI(url) uri.query = URI.encode_www_form(data) res = Net::HTTP.get_response(uri) res.body end