Class: Giddy::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(username, password, token = nil, secure_token = nil) ⇒ Client

Returns a new instance of Client.



3
4
5
# File 'lib/giddy/client.rb', line 3

def initialize(username, password, token=nil, secure_token=nil)
  @mediator = Mediator.new(username, password, token, secure_token)
end

Instance Method Details

#create_lightbox(name, attrs) ⇒ Object



45
46
47
48
# File 'lib/giddy/client.rb', line 45

def create_lightbox(name, attrs)
  attrs = { :LightboxName => name }.merge(attrs)
  LightboxHeaders.new(@mediator).create_lightbox(attrs)
end

#create_sessionObject

not necessary typically, sessions will be autocreated



59
60
61
# File 'lib/giddy/client.rb', line 59

def create_session
  @mediator.create_session
end

#get_lightbox(id) ⇒ Object



40
41
42
43
# File 'lib/giddy/client.rb', line 40

def get_lightbox(id)
  attrs = { :LightboxId => id, :LightboxItemsViewOptions => { :ItemCount => 100, :ItemStartNumber => 1 } }
  LightboxHeaders.new(@mediator).get_lightbox(attrs)
end

#lightboxes(count = 1, start = 1) ⇒ Object



33
34
35
36
37
38
# File 'lib/giddy/client.rb', line 33

def lightboxes(count=1, start=1)
  attrs = {
    :ResultsViewOptions => { :ItemCount => count, :ItemStartNumber => start }
  }
  LightboxHeaders.new(@mediator).get_lightbox_headers(attrs)
end

#search(attrs) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/giddy/client.rb', line 11

def search(attrs)
  if attrs.has_key?(:image_id) and attrs.keys.length == 1
    return Search.new(@mediator).get_image_details(attrs[:image_id]).first
  elsif attrs.has_key?(:image_ids) and attrs.keys.length == 1
    return Search.new(@mediator).get_image_details(attrs[:image_ids])
  end
  
  attrs = {
    :limit => 25,
    :start => 1,
    :query => "",
    :additional => {}
  }.merge(attrs)

  converted = {
    :Query => { :SearchPhrase =>  attrs[:query] },
    :ResultOptions => { :ItemCount => attrs[:limit], :ItemStartNumber => attrs[:start] }
  }
  attrs = converted.merge(attrs[:additional])
  Search.new(@mediator).search_for_images(attrs)
end

#secure_tokenObject



54
55
56
# File 'lib/giddy/client.rb', line 54

def secure_token
  @mediator.secure_token
end

#set_system_credentials(system_id, system_password) ⇒ Object



7
8
9
# File 'lib/giddy/client.rb', line 7

def set_system_credentials(system_id, system_password)
  @mediator.set_system_credentials system_id, system_password
end

#tokenObject



50
51
52
# File 'lib/giddy/client.rb', line 50

def token
  @mediator.token
end