class Minly::Url
Attributes
connection[R]
response[R]
status[R]
token[RW]
Public Class Methods
new(token = nil)
click to toggle source
# File lib/minly/url.rb, line 12 def initialize(token = nil) @connection = Faraday.new(:url => API_URL) @token = token end
Public Instance Methods
change_minly_status(url, data)
click to toggle source
# File lib/minly/url.rb, line 50 def change_minly_status(url, data) return false if has_no_token_error params = { "url[active]" => data, user_token: token } process_response connection.put("/urls/#{url}.json", params) end
change_minly_target(url, target)
click to toggle source
# File lib/minly/url.rb, line 41 def change_minly_target(url, target) return false if has_no_token_error params = { "url[original]" => target, user_token: token } process_response connection.put("/urls/#{url}.json", params) end
create_minly(url, vanity_string = '')
click to toggle source
# File lib/minly/url.rb, line 29 def create_minly(url, vanity_string = '') return false if (vanity_string.nil? || (!vanity_string.empty? && has_no_token_error) ) @token ||= 0 params = { "url[shortened]" => vanity_string, "url[original]" => url, "user_token" => token } process_response connection.post("/urls.json", params) # user_token=vBIPTJtcHX7cORPGjFXOLvIzKU9hmHX05FST_t-sY6s end
destroy_minly(url)
click to toggle source
# File lib/minly/url.rb, line 59 def destroy_minly(url) return false if has_no_token_error params = { user_token: token } process_response connection.delete("/urls/#{url}.json", params) end
expand_minly(url)
click to toggle source
# File lib/minly/url.rb, line 17 def expand_minly(url) make_get_request(API_SHOW_ACTION + "expand/" + url) end
has_no_token_error()
click to toggle source
# File lib/minly/url.rb, line 87 def has_no_token_error if !token || token == 0 @status = {type: "error", info: "Request requires a valid user token."} return true end false end
make_get_request(request)
click to toggle source
# File lib/minly/url.rb, line 77 def make_get_request(request) process_response(connection.get(request)) end
parse_status(response)
click to toggle source
# File lib/minly/url.rb, line 95 def parse_status(response) {type: response["status"], info: response["status_info"]} end
popular_minlys()
click to toggle source
# File lib/minly/url.rb, line 21 def popular_minlys make_get_request(API_SHOW_ACTION + "popular/") end
process_response(response)
click to toggle source
# File lib/minly/url.rb, line 81 def process_response(response) response = JSON.parse(response.body) @status = parse_status(response) @response = response["payload"] end
recent_minlys()
click to toggle source
# File lib/minly/url.rb, line 25 def recent_minlys make_get_request(API_SHOW_ACTION + "recent/") end
update_minly(url, origin, active)
click to toggle source
# File lib/minly/url.rb, line 67 def update_minly(url, origin, active) return false if (has_no_token_error || !origin || origin.empty? || active.nil?) params = { "url[active]" => active, "url[orignal]" => origin, user_token: token } process_response connection.put("/urls/#{url}.json", params) end