lib/instapaper/client.rb in instapaper-0.3.0 vs lib/instapaper/client.rb in instapaper-1.0.0.pre2
- old
+ new
@@ -1,43 +1,55 @@
-require 'instapaper/connection'
-require 'instapaper/request'
-require 'instapaper/authentication'
+require 'instapaper/api'
+require 'instapaper/http/utils'
+require 'instapaper/version'
module Instapaper
# Wrapper for the Instapaper REST API
class Client
- # @private
- attr_accessor *Configuration::VALID_OPTIONS_KEYS
+ include Instapaper::API
+ include Instapaper::HTTP::Utils
- alias :api_endpoint :endpoint
- alias :api_version :version
+ attr_accessor :oauth_token, :oauth_token_secret, :consumer_key, :consumer_secret, :proxy
+ attr_writer :user_agent
- # Creates a new API
- def initialize(options={})
- options = Instapaper.options.merge(options)
- Configuration::VALID_OPTIONS_KEYS.each do |key|
- send("#{key}=", options[key])
+ # Initializes a new Client object
+ #
+ # @param options [Hash]
+ # @return [Instapaper::Client]
+ def initialize(options = {})
+ options.each do |key, value|
+ instance_variable_set("@#{key}", value)
end
+ yield(self) if block_given?
end
- def endpoint_with_prefix
- api_endpoint + path_prefix
+ # @return [String]
+ def user_agent
+ @user_agent ||= "InstapaperRubyGem/#{Instapaper::VERSION}"
end
- include Connection
- include Request
- include Authentication
+ # Authentication hash
+ #
+ # @return [Hash]
+ def credentials
+ {
+ consumer_key: @consumer_key,
+ consumer_secret: @consumer_secret,
+ oauth_token: @oauth_token,
+ oauth_token_secret: @oauth_token_secret,
+ }
+ end
- # Require client method modules after initializing the Client class in
- # order to avoid a superclass mismatch error, allowing those modules to be
- # Client-namespaced.
- require 'instapaper/client/account'
- require 'instapaper/client/user'
- require 'instapaper/client/bookmark'
- require 'instapaper/client/folder'
+ # @return [Hash]
+ def consumer_credentials
+ {
+ consumer_key: @consumer_key,
+ consumer_secret: @consumer_secret,
+ }
+ end
- include Instapaper::Client::Account
- include Instapaper::Client::User
- include Instapaper::Client::Bookmark
- include Instapaper::Client::Folder
+ # @return [Boolean]
+ def credentials?
+ credentials.values.all?
+ end
end
end