Class: RestBooks::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



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/restbooks.rb', line 48

def initialize( options={} )
  # Set host
  host = options.has_key?( :host ) ? options.delete(:host) : 'http://feedbooks.com'
  
  # Set user-agent
  @user_agent = options.has_key?( :user_agent ) ? options.delete( :user_agent ) : "RestBooks 0.1"

  # Set service URI
  @uri = URI.parse( host )

  # Set authentification
  if options.has_key?( :user ) && options.has_key?( :password )
    @uri.user = options.delete( :user )
    @uri.password = Digest::MD5.hexdigest( options.delete( :password ) )
  end

  # Set logger output
  RestClient.log = options.delete( :log ) if options.has_key?( :log )

  # Init services
  @books = false
  @authors = false
  @lists = false
  @categories = false
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



46
47
48
# File 'lib/restbooks.rb', line 46

def uri
  @uri
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



46
47
48
# File 'lib/restbooks.rb', line 46

def user_agent
  @user_agent
end

Instance Method Details

#authorsObject

Use this object to acess authors resource



81
82
83
84
# File 'lib/restbooks.rb', line 81

def authors
  @authors = Authors.new( self ) if !@authors
  return @authors
end

#booksObject

Use this object to acess books resource



75
76
77
78
# File 'lib/restbooks.rb', line 75

def books
  @books = Books.new( self ) if !@books
  return @books
end

#categoriesObject

Use this object to acess categories resource



93
94
95
96
# File 'lib/restbooks.rb', line 93

def categories
  @categories = Categories.new( self ) if !@categories
  return @categories
end

#listsObject

Use this object to acess lists resource



87
88
89
90
# File 'lib/restbooks.rb', line 87

def lists
  @lists = Lists.new( self ) if !@lists
  return @lists
end