Skip to content

Commit

Permalink
Merge branch 'brancusi-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
asoesilo committed Feb 1, 2015
2 parents 9c811ea + d99b202 commit a5d4afa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/routific.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ def getRoute(data, token = @@token)
raise ArgumentError, "access token must be set"
end

# Sends HTTP request to Routific API server
# Prefix the token with "bearer " if missing during assignment
prefixed_token = (/bearer /.match(token).nil?) ? "bearer #{token}" : token

begin
# Sends HTTP request to Routific API server
response = RestClient.post('https://routific.com/api/vrp',
data.to_json,
'Authorization' => "bearer #{token}",
'Authorization' => prefixed_token,
content_type: :json,
accept: :json
)
Expand Down
10 changes: 8 additions & 2 deletions spec/routific_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
end

it "returns a Route instance" do
route = routific.getRoute()
route = routific.getRoute()
expect(route).to be_instance_of(Route)
end
end
Expand Down Expand Up @@ -175,8 +175,14 @@
it "returns a Route instance" do
expect(Routific.getRoute(@data, ENV["API_KEY"])).to be_instance_of(Route)
end

it "still successful even if missing prefix 'bearer ' in key" do
key = ENV["API_KEY"].sub /bearer /, ''
expect(/bearer /.match(key).nil?).to be true
expect(Routific.getRoute(@data, key)).to be_instance_of(Route)
end
end
end
end
end
end
end

0 comments on commit a5d4afa

Please sign in to comment.