Skip to content

Commit

Permalink
Merge pull request #34 from faber/master
Browse files Browse the repository at this point in the history
API calls over SSL
  • Loading branch information
codingjester committed Nov 17, 2014
2 parents 63eca74 + 99a610f commit ffc24d9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/tumblr/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def api_host
self.class.default_api_host
end

def api_scheme
@api_scheme || 'https'
end

def credentials
{
:consumer_key => @consumer_key,
Expand Down
3 changes: 2 additions & 1 deletion lib/tumblr/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Config
:consumer_secret,
:oauth_token,
:oauth_token_secret,
:client
:client,
:api_scheme
]

attr_accessor *VALID_OPTIONS_KEYS
Expand Down
4 changes: 2 additions & 2 deletions lib/tumblr/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def connection(options={})
:accept => 'application/json',
:user_agent => "tumblr_client (ruby) - #{Tumblr::VERSION}"
},
:url => "http://#{api_host}/"
:url => "#{api_scheme}://#{api_host}/"
}

client = Faraday.default_adapter

Faraday.new("http://#{api_host}/", default_options.merge(options)) do |conn|
Faraday.new(default_options.merge(options)) do |conn|
data = { :api_host => api_host }.merge(credentials)
unless credentials.empty?
conn.request :oauth, data
Expand Down
20 changes: 20 additions & 0 deletions spec/examples/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,24 @@

end

describe :api_scheme do

it 'defaults to https' do
expect(Tumblr::Client.new.api_scheme).to eq('https')
end

it 'can be set by the initializer' do
client = Tumblr::Client.new(:api_scheme => 'http')
expect(client.api_scheme).to eq('http')
end

it 'can be set globally' do
Tumblr.configure do |c|
c.api_scheme = 'http'
end
expect(Tumblr::Client.new.api_scheme).to eq('http')
end

end

end

0 comments on commit ffc24d9

Please sign in to comment.