Class: Rubilicious

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiclious/delicious_api.rb,
lib/graphiclious/delicious_api.rb,
lib/graphiclious/delicious_api.rb

Overview

#all() and #recent() shoult return the same format therefore I changed ‘tag’ into ‘tags’

Instance Method Summary collapse

Instance Method Details

#all(tag = nil) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/graphiclious/delicious_api.rb', line 9

def all(tag = nil)
  args = [(tag ? "tag=#{tag.uri_escape}" : nil)]
  get('posts/all?' << args.compact.join('&amp;'), 'post').map do |e|
    e['time'] = Time::from_iso8601(e['time'])
    e['tags'] = e['tag'].split(/\s/) # wrong in 1.5

    e # missing in 1.5

  end
end

#http_get(url) ⇒ Object

del.icio.us-API change 08/2006!



75
76
77
# File 'lib/graphiclious/delicious_api.rb', line 75

def http_get(url)
  https_get(url)
end

#https_get(url) ⇒ Object

Low-level HTTPS GET. SDo used the tip at ruby.about.com/od/tutorials/ss/delicious_tags_4.htm to get Rubilicious code working



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/graphiclious/delicious_api.rb', line 44

def https_get(url)
  # get proxy info

  proxy_host, proxy_port = find_http_proxy
  # $stderr.puts "DEBUG: proxy: host = #{proxy_host}, port = #{proxy_port}"

  
  # get host, port, and base URI for API queries

  uri = URI::parse(@base_uri)
  base = uri.request_uri
  
  # prepend base to url

  url = "#{base}/#{url}"
  
  # connect to delicious

  http = Net::HTTP.Proxy(proxy_host, proxy_port).new(uri.host, uri.port)
  http.use_ssl = true
  http.start
  
  # get URL, check for error

  resp = http.get(url, @headers)
  unless resp.code =~ /2\d{2}/
    puts base
    puts url
    raise "HTTP #{resp.code}: #{resp.message}"
  end
  
  # close HTTP connection, return response

  http.finish
  resp.body
end