lib/feedly_api.rb in feedly_api-0.4.2 vs lib/feedly_api.rb in feedly_api-0.5.0
- old
+ new
@@ -1,30 +1,39 @@
# encoding: utf-8
require 'feedly_api/version'
require 'feedly_api/errors'
-require 'feedly_api/api'
require 'feedly_api/client'
+require 'feedly_api/feed'
module FeedlyApi
- class Feed
- attr_reader :url, :subscribers, :title, :velocity, :id
+ API_ENDPOINT = 'http://cloud.feedly.com/v3/'.freeze
- def initialize(url)
- @url = url
- @id = "feed%2F#{CGI.escape(@url)}"
- get_info
- end
+ class << self
+ def get(url, token)
+ uri = URI(url)
+ req = Net::HTTP::Get.new(uri)
- def get_info
- json = Api.fetch(:feeds, @id)
- @subscribers = json.fetch(:subscribers) { nil }
- @title = json.fetch(:title) { nil }
- @velocity = json.fetch(:velocity) { nil }
- end
+ unless token.nil?
+ req['$Authorization.feedly'] = '$FeedlyAuth'
+ req['Authorization'] = "OAuth #{token}"
+ end
- def items(params = {})
- Api.fetch(:streams, @id, params).fetch(:items)
+ response = Net::HTTP.start(uri.hostname, uri.port) do |http|
+ http.request(req)
+ end
+
+ raise BadRequest if 'null' == response.body
+
+ case response.code.to_i
+ when 200 then response.body
+ when 401 then raise AuthError
+ when 403 then raise AuthError
+ when 404 then raise NotFound
+ when 500 then raise Error
+ else
+ raise Error
+ end
end
end
require 'cgi'
require 'net/http'