Module: Url2png

Extended by:
Url2png
Included in:
Url2png
Defined in:
lib/url2png/config.rb,
lib/url2png/dimensions.rb,
lib/url2png/helpers/common.rb

Defined Under Namespace

Modules: Dimensions, Helpers

Constant Summary collapse

MODES =

modes

%w{production placehold dummy}
API_URL =
'http://beta.url2png.com'

Instance Method Summary collapse

Instance Method Details

#api_keyObject



23
24
25
26
# File 'lib/url2png/config.rb', line 23

def api_key
  raise 'Url2png error: No public key defined!' if @api_key.nil?
  @api_key
end

#api_key=(api_key) ⇒ Object



19
20
21
# File 'lib/url2png/config.rb', line 19

def api_key=api_key
  @api_key=api_key
end

#api_urlObject



58
59
60
61
62
# File 'lib/url2png/config.rb', line 58

def api_url
  # reference => http://url2png.com/docs/
  # currently all versions suggest 'beta'
  @api_url || API_URL
end

#api_url=(api_url) ⇒ Object



54
55
56
# File 'lib/url2png/config.rb', line 54

def api_url=api_url
  @api_url = api_url || API_URL
end

#api_versionObject



50
51
52
# File 'lib/url2png/config.rb', line 50

def api_version
  @api_version || 'v6' #default: v6
end

#api_version=(api_version) ⇒ Object



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

def api_version=api_version
  @api_version = api_version || 'v6' # set default to latest open version
end

#config(c = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/url2png/config.rb', line 8

def config c = {}
  # mandatory
  self.api_key = c[:api_key]
  self.private_key = c[:private_key]

  # optional
  self.mode = c[:mode] if c[:mode]
  self.api_version = c[:api_version] if c[:api_version]
  self.api_url = c[:api_url] if c[:api_url]
end

#default_sizeObject



68
69
70
# File 'lib/url2png/config.rb', line 68

def default_size
  @default_size || "400x400"
end

#default_size=(default_size) ⇒ Object



64
65
66
# File 'lib/url2png/config.rb', line 64

def default_size=default_size
  @default_size = default_size || "400x400"
end

#modeObject



42
43
44
# File 'lib/url2png/config.rb', line 42

def mode
  @mode ||= 'production' # default: production
end

#mode=(mode) ⇒ Object



37
38
39
40
# File 'lib/url2png/config.rb', line 37

def mode=mode
  raise "Url2png error: Invalid mode, only #{ MODES.join(', ') } are allowed" unless MODES.include?(mode.to_s)
  @mode = mode.to_s
end

#private_keyObject



32
33
34
35
# File 'lib/url2png/config.rb', line 32

def private_key
  raise 'Url2png error: No private key defined!' if @private_key.nil?
  @private_key
end

#private_key=(private_key) ⇒ Object



28
29
30
# File 'lib/url2png/config.rb', line 28

def private_key=private_key
  @private_key = private_key
end

#token(param) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/url2png/config.rb', line 72

def token param
  case self.api_version
  when 'v6'
    Digest::MD5.hexdigest("#{param}#{self.private_key}")
  when 'v4', 'v3'
    Digest::MD5.hexdigest("#{self.private_key}+#{param}")
  end
end