Class: Mediaplug::Client
- Inherits:
-
Object
- Object
- Mediaplug::Client
- Includes:
- HTTParty
- Defined in:
- lib/mediaplug/client.rb
Instance Method Summary collapse
- #get_result(resource = '', args = {}) ⇒ Object
-
#initialize(server, access_id) ⇒ Client
constructor
A new instance of Client.
- #shorten(input, opts = {}) ⇒ Object
Constructor Details
#initialize(server, access_id) ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/mediaplug/client.rb', line 9 def initialize(server, access_id) self.class.base_uri server @access_id = access_id end |
Instance Method Details
#get_result(resource = '', args = {}) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/mediaplug/client.rb', line 21 def get_result(resource='', args={}) args = args.merge({'url[access_id]' => @access_id}) begin result = self.class.post(resource, :query => args).parsed_response rescue Exception => e result = {'errorMessage' => e., 'errorCode' => 69, 'statusCode' => 'ERROR'} end end |
#shorten(input, opts = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/mediaplug/client.rb', line 14 def shorten(input, opts={}) result = get_result("/urls", 'url[url]' => input)['url']['code'] result = self.class.base_uri+"/"+result rescue raise MediaplugError.new('error shorten the url.', 100) end |