Skip to content

Commit

Permalink
make api_url as configurable
Browse files Browse the repository at this point in the history
hereby it is able to:
1. refer to different api urls (beta | api)
2. opt for protocol less urls to work with ssl connection
  • Loading branch information
robinhoudmeyers committed Jan 7, 2013
1 parent 89a4bfa commit 15602f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/url2png/config.rb
Expand Up @@ -3,6 +3,7 @@ module Url2png

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

def config c = {}
# mandatory
Expand All @@ -12,6 +13,7 @@ def config c = {}
# 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

def api_key=api_key
Expand Down Expand Up @@ -49,6 +51,16 @@ def api_version
@api_version || 'v6' #default: v6
end

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

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

def default_size=default_size
@default_size = default_size || "400x400"
end
Expand Down
7 changes: 3 additions & 4 deletions lib/url2png/helpers/common.rb
Expand Up @@ -111,8 +111,7 @@ def url2png_image_url url, options = {}

# set the format of the asset requested
format = options[:format] || "png"

"http://api.url2png.com/v6/#{Url2png.api_key}/#{token}/#{format}/?#{query_string}"
"#{ Url2png.api_url }/v6/#{Url2png.api_key}/#{token}/#{format}/?#{query_string}"

when 'v4'
######
Expand Down Expand Up @@ -144,7 +143,7 @@ def url2png_image_url url, options = {}

# build image url
File.join(
"http://beta.url2png.com",
"#{Url2png.api_url}",
Url2png.api_version,
Url2png.api_key,
token,
Expand Down Expand Up @@ -180,7 +179,7 @@ def url2png_image_url url, options = {}

# build image url
File.join(
"http://api.url2png.com",
"#{Url2png.api_url}",
Url2png.api_version,
Url2png.api_key,
token,
Expand Down

0 comments on commit 15602f8

Please sign in to comment.