Class: Gazette::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gazette/client.rb

Overview

The Client class interacts with the Instapaper API. Client hold user authentication information, as well as provide methods to authenticate user credentials and add URLs to their user’s Instapaper account.

See Also:

Author:

  • Jeff Pollard

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, options = {}) ⇒ Client

Create a new client. Instapaper requires a user username. Most Instapaper users don’t have a password, as such it is optional.

Parameters:

  • username (String)

    Instapaper username

  • options (Hash) (defaults to: {})

    Additional client options

Options Hash (options):

  • :password (String)

    Instapaper username

  • :https (Boolean) — default: false

    Interact with the Instapaper API over HTTPS.

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
# File 'lib/gazette/client.rb', line 26

def initialize(username, options = {})
  raise ArgumentError.new("2nd parameter must be a Hash") unless options.is_a?(Hash)
  @username = username
  @password = options.delete(:password)
  @options = options
  @https = !!(options.delete(:https))
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#add(url, options = {}) ⇒ Response::Success

Adds a URL to a user’s instapaper account.

Parameters:

  • url (String)

    URL of the content to add.

  • options (Hash) (defaults to: {})

    Additional add options

Options Hash (options):

  • :title (String)

    Title of the content. If omitted, Instapaper will generate a title.

  • :select (String)

    Sample/selection of content.

  • :redirect (:close)

    Response returns “Saved!” string and attempts to close its own window after a short delay.

  • :jsonp (String) — default: nil

    Returns results as JSON to the specified Javascript callback.

Returns:

Raises:



62
63
64
# File 'lib/gazette/client.rb', line 62

def add(url, options = {})
  parse_response_for request(:add, options.merge(:url => url))
end

#authenticate(options = {}) ⇒ Response::Success

Attempts to authenticate the client’s user credentials with Instapaper.

Parameters:

  • options (Hash) (defaults to: {})

    Additional authentication options

Options Hash (options):

  • :jsonp (String) — default: nil

    Returns results as JSON to the specified Javascript callback.

Returns:

Raises:



43
44
45
# File 'lib/gazette/client.rb', line 43

def authenticate(options = {})
  parse_response_for request(:authenticate, options)
end