Skip to content

Commit

Permalink
Merge remote-tracking branch 'jvirtanen/cleanups/client'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/reittiopas2/client.rb
	lib/reittiopas2/routing.rb
  • Loading branch information
orva committed Jan 19, 2014
2 parents 3f59874 + 79cc8a3 commit 05c89b1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/reittiopas2.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'reittiopas2/connection'
require 'reittiopas2/client'
require 'reittiopas2/geocoding'
require 'reittiopas2/routing'
require 'reittiopas2/utilities'
Expand All @@ -9,7 +9,7 @@ class Reittiopas2
include Routing

def initialize(username, password)
@connection = Reittiopas2::Connection.new(username, password)
@client = Reittiopas2::Client.new(username, password)
end
end

4 changes: 2 additions & 2 deletions lib/reittiopas2/connection.rb → lib/reittiopas2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class Reittiopas2
# parsing response into Ruby readable form.
#
# @api private
class Connection
class Client
include Utilities

def initialize(username, password)
@base_url = "http://api.reittiopas.fi/hsl/prod/"
@base_query = {"user" => username, "pass" => password}
end

# Forms proper query from credentials + given query and sends it to API
# endpoint. Also parses response into Ruby readable form.
#
Expand Down
4 changes: 2 additions & 2 deletions lib/reittiopas2/geocoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module Geocoding
def geocode(place_name, opts={})
clean = select_keys(opts, GEOCODE_KEYS)
query = {'request' =>'geocode', 'key' => place_name}.merge(clean)
@connection.perform_query(query)
@client.perform_query(query)
end

# Do reverse geocode search to find information about given coordinates.
Expand All @@ -96,7 +96,7 @@ def geocode(place_name, opts={})
def reverse_geocode(coords, opts={})
clean = select_keys(opts, REVERSE_GEOCODE_KEYS)
query = {'request' => 'reverse_geocode', 'coordinate' => coords}.merge(clean)
@connection.perform_query(query)
@client.perform_query(query)
end

GEOCODE_KEYS = ['key', 'cities', 'loc_types', 'disable_error_correction',
Expand Down
2 changes: 1 addition & 1 deletion lib/reittiopas2/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def route(from, to, opts={})
end

clean_opts = select_keys(opts, KEYS + MODE_COSTS)
@connection.perform_query(clean_opts.merge(query))
@client.perform_query(clean_opts.merge(query))
end

private
Expand Down
16 changes: 8 additions & 8 deletions spec/connection_spec.rb → spec/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'spec_helper'

describe Reittiopas2::Connection do
describe Reittiopas2::Client do
before :each do
@user = "username"
@pwd = "password"
@conn = Reittiopas2::Connection.new @user, @pwd
@client = Reittiopas2::Client.new @user, @pwd

@base_url = "http://api.reittiopas.fi/hsl/prod/"
@query = {"user" => @user, "pass" => @pwd}
Expand All @@ -18,15 +18,15 @@
stub_request(:get, @base_url).
with(:query => expected_q)

@conn.perform_query(q)
@client.perform_query(q)
a_request(:get, @base_url).with(:query => expected_q).should have_been_made
end

it "should form query only with credentials in case no query given." do
stub_request(:get, @base_url).
with(:query => @query)

@conn.perform_query
@client.perform_query
a_request(:get, @base_url).with(:query => @query).should have_been_made
end
end
Expand All @@ -40,7 +40,7 @@
with(:query => query).
to_return(:body => body)

ret = @conn.perform_query(query)
ret = @client.perform_query(query)
ret.should == {"max" => 5000, "used" => 44}
end

Expand All @@ -51,7 +51,7 @@
with(:query => @query).
to_return(:status => 500, :body => body)

ret = @conn.perform_query
ret = @client.perform_query
ret.should == {'error' => body}
end

Expand All @@ -62,7 +62,7 @@
with(:query => @query).
to_return(:body => body)

ret = @conn.perform_query
ret = @client.perform_query
ret['error'].should_not be_nil
end

Expand All @@ -71,7 +71,7 @@
with(:query => @query).
to_return(:body => '')

ret = @conn.perform_query
ret = @client.perform_query
ret.should == {'error' => 'Response body was empty!'}
end
end
Expand Down

0 comments on commit 05c89b1

Please sign in to comment.