Class: Tasty

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/tasty.rb

Constant Summary collapse

VERSION =
'1.0.1'.freeze
DEFAULT_HEADERS =
{
  'User-Agent' => "tasty gem #{VERSION}"
}
DELICIOUS_API_URL =
'https://api.del.icio.us/v1/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, delicious_api_url = DELICIOUS_API_URL) ⇒ Tasty

Initialize with your API token



20
21
22
23
24
# File 'lib/tasty.rb', line 20

def initialize(username, password, delicious_api_url = DELICIOUS_API_URL)
  @username = username
  @password = password
  @delicious_api_url = delicious_api_url
end

Instance Attribute Details

#delicious_api_urlObject

Returns the value of attribute delicious_api_url.



15
16
17
# File 'lib/tasty.rb', line 15

def delicious_api_url
  @delicious_api_url
end

#passwordObject

Returns the value of attribute password.



17
18
19
# File 'lib/tasty.rb', line 17

def password
  @password
end

#usernameObject

Returns the value of attribute username.



16
17
18
# File 'lib/tasty.rb', line 16

def username
  @username
end

Instance Method Details

#debug(location = $stderr) ⇒ Object



26
27
28
# File 'lib/tasty.rb', line 26

def debug(location = $stderr)
  self.class.debug_output(location)
end

#get(api_method, options = {}) ⇒ Object

Call del.icio.us using a particular API method, api_method. The options hash is where you can add any parameters appropriate for the API call.



40
41
42
43
44
45
46
# File 'lib/tasty.rb', line 40

def get(api_method, options = {})
  query = {}
  query.merge!(authorization_hash)
  query.merge!({:query => options})
        
  self.class.get(@delicious_api_url + api_method, query)
end

#post(api_method, options = {}) ⇒ Object

Post to del.icio.us using a particular API method, api_method. The parameters hash is where you add all the required parameters appropriate for the API call.



49
50
51
52
53
54
55
# File 'lib/tasty.rb', line 49

def post(api_method, options = {}) 
  query = {}
  query.merge!(authorization_hash)
  query.merge!({:body => options})
            
  self.class.post(@delicious_api_url + api_method, query)    
end

#set_http_headers(http_headers = {}) ⇒ Object



30
31
32
33
# File 'lib/tasty.rb', line 30

def set_http_headers(http_headers = {})
  http_headers.merge!(DEFAULT_HEADERS)
  headers(http_headers)
end

#set_timeout(timeout) ⇒ Object



35
36
37
# File 'lib/tasty.rb', line 35

def set_timeout(timeout)
  default_timeout(timeout)
end