Module: Smile::Common

Included in:
Base, Base
Defined in:
lib/smile/common.rb

Constant Summary

BASE =
'http://api.smugmug.com/hack/json/1.2.0/'
BASE_SECURE =
'https://api.smugmug.com/hack/json/1.2.0/'
UPLOAD =
"http://upload.smugmug.com/"
VERSION =
'1.2.0'

Instance Method Summary (collapse)

Instance Method Details

- (Object) base_web_method_call(web_options, options = {}, url)

Call either the secure or the base web url



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/smile/common.rb', line 35

def base_web_method_call( web_options, options ={}, url )
    options     = Smile::ParamConverter.clean_hash_keys( options )
    web_options = Smile::ParamConverter.clean_hash_keys( web_options )

    params = default_params.merge( web_options )
    params.merge!( options ) if( options )

    logger.info( params.inspect )

    json = RestClient.post( url, params ).body
    upper_hash_to_lower_hash( Smile::Json.parse( json ) )
end

- (Object) default_params

This will be included in every request once you have logged in



14
15
16
17
18
# File 'lib/smile/common.rb', line 14

def default_params
  @params ||= { :api_key => session.api_key }
  @params.merge!( :session_id => session.id ) if( session.id )
  @params = Smile::ParamConverter.clean_hash_keys( @params )
end

- (Object) logger



63
64
65
# File 'lib/smile/common.rb', line 63

def logger
  session.logger
end

- (Boolean) logger_on?



67
68
69
# File 'lib/smile/common.rb', line 67

def logger_on?
  session.logger_on?
end

- (Object) secure_web_method_call(web_options, options = {})

This is the base work that will need to be done on ALL web calls. Given a set of web options and other params call the web service and convert it to json



30
31
32
# File 'lib/smile/common.rb', line 30

def secure_web_method_call( web_options, options = {} )
			base_web_method_call( web_options, options, BASE_SECURE )
end

- (Object) session



9
10
11
# File 'lib/smile/common.rb', line 9

def session
  @session ||= Session.instance
end

- (Object) upper_hash_to_lower_hash(upper)

This converts a hash that has mixed case into all lower case



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

def upper_hash_to_lower_hash( upper )
			case upper
			when Hash
    upper.inject({}) do |lower,array|
	key, value = array
      lower[key.downcase] = upper_hash_to_lower_hash( value )
	lower
    end
  else
    upper
  end
end

- (Object) web_method_call(web_options, options = {})

This is the base work that will need to be done on ALL web calls. Given a set of web options and other params call the web service and convert it to json



23
24
25
# File 'lib/smile/common.rb', line 23

def web_method_call( web_options, options = {} )
			base_web_method_call( web_options, options, BASE )
end