Class: RSimpy::Links

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login = nil, pass = nil) ⇒ Links

Returns a new instance of Links.



9
10
11
12
13
14
15
# File 'lib/links.rb', line 9

def initialize(=nil, pass=nil)
  if ( && pass)
    @user = RSimpy::User.new , pass
  else
    @user = get_user_from_file
  end
end

Instance Attribute Details

#status_codeObject (readonly)

TODO move this functionality to RSimpy module



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

def status_code
  @status_code
end

#status_messageObject (readonly)

TODO move this functionality to RSimpy module



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

def status_message
  @status_message
end

#successObject (readonly)

TODO move this functionality to RSimpy module



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

def success
  @success
end

Instance Method Details

#execute(service, params) ⇒ Object



43
44
45
46
47
48
# File 'lib/links.rb', line 43

def execute service, params
  set_codes
  response = service.execute params
  set_codes service
  response
end

#get_user_from_fileObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/links.rb', line 17

def get_user_from_file
  storage_service = RSimpy::ProfileStorageService.new
  config = RSimpy::Configuration.new storage_service

  if !config.stored?
    raise UserNotProvidedError "Please configure RSimpy or supply username and password"
  end

  config.get
end

#save(params) ⇒ Object



28
29
30
31
# File 'lib/links.rb', line 28

def save params
  params.add(:accessType, :public) unless params.has_key? :accessType
  execute RSimpy::PostingService.new(RSimpy::SAVE_LINK, RSimpy::Client.new(@user)), params
end

#set_codes(service = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/links.rb', line 50

def set_codes service=nil
  if service
    @success = service.success
    @status_code = service.status_code
    @status_message = service.status_message
  else
    @success = false
    @status_code = nil
    @status_message =nil
  end
end