lib/feedly_api.rb in feedly_api-0.3b vs lib/feedly_api.rb in feedly_api-0.4b
- old
+ new
@@ -1,63 +1,34 @@
# encoding: utf-8
-module FeedlyApi
- VERSION = '0.3b'
- API_ENDPOINT = 'http://cloud.feedly.com/v3/'
+require 'feedly_api/version'
+require 'feedly_api/errors'
+require 'feedly_api/api'
+require 'feedly_api/client'
+module FeedlyApi
class Feed
attr_reader :url, :subscribers, :title, :velocity
def initialize(url)
@url = url
+ @id = "feed%2F#{CGI.escape(@url)}"
get_info
end
def get_info
- url = API_ENDPOINT
- url += 'feeds/feed%2F'
- url += CGI.escape(@url)
- json = JSON.parse(get(url))
-
- @subscribers = json['subscribers']
- @title = json['title']
- @velocity = json['velocity']
+ json = Api.fetch(:feeds, @id)
+ @subscribers = json.fetch(:subscribers)
+ @title = json.fetch(:title)
+ @velocity = json.fetch(:velocity)
end
def items(params = {})
- json = JSON.parse(get(construct_url(params)), symbolize_names: true)
- json[:items]
+ Api.fetch(:streams, @id, params).fetch(:items)
end
-
- private
-
- def construct_url(options)
- params = options.map { |k,v| "#{k.to_s}=#{v.to_s}&" }.join
- url = FeedlyApi::API_ENDPOINT
- url += 'streams/feed%2F'
- url += CGI.escape(@url)
- url += '/contents?'
- url += "ck=#{Time.now.to_i}000&"
- url += params
- end
-
- def get(url)
- response = Net::HTTP.get_response(URI(url))
- raise unless 200 == response.code.to_i
- response.body
- end
end
- class Client
- def initialize(auth_token = nil)
- @auth_token = auth_token
- end
-
- def feed(feed_url)
- FeedlyApi::Feed.new feed_url
- end
- end
-
require 'cgi'
require 'net/http'
require 'json'
+ require 'date'
end