diff --git a/lib/tumblr/client.rb b/lib/tumblr/client.rb index b0c3d6a..236fda6 100644 --- a/lib/tumblr/client.rb +++ b/lib/tumblr/client.rb @@ -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, diff --git a/lib/tumblr/config.rb b/lib/tumblr/config.rb index bef327e..0aa8517 100644 --- a/lib/tumblr/config.rb +++ b/lib/tumblr/config.rb @@ -6,7 +6,8 @@ module Config :consumer_secret, :oauth_token, :oauth_token_secret, - :client + :client, + :api_scheme ] attr_accessor *VALID_OPTIONS_KEYS diff --git a/lib/tumblr/connection.rb b/lib/tumblr/connection.rb index fe259e2..8cd3ca6 100644 --- a/lib/tumblr/connection.rb +++ b/lib/tumblr/connection.rb @@ -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 diff --git a/spec/examples/client_spec.rb b/spec/examples/client_spec.rb index 1cdab6b..2df6183 100644 --- a/spec/examples/client_spec.rb +++ b/spec/examples/client_spec.rb @@ -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