Skip to content

Commit

Permalink
Merge pull request #4 from apoex/17493-use-faraday
Browse files Browse the repository at this point in the history
[#17493] Use faraday
  • Loading branch information
Hornwall authored May 14, 2020
2 parents 8e3a477 + c2d58c1 commit b0c7bde
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 15 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ How to fetch a package with the test identifier from [developer documentation](h
```ruby
> response = Postnord.find_by_identifier('84971563697SE')
> response.code # => 200
> response.status # => OK
> response.data # => {"TrackingInformationResponse"=>{"shipments"=>[]}}
```

Expand Down
3 changes: 1 addition & 2 deletions lib/postnord.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'faraday'
require 'uri'
require 'net/http'
require 'net/https'
require 'json'
require 'openssl'

Expand Down
5 changes: 1 addition & 4 deletions lib/postnord/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ def do_request(service, endpoint, params={})
)

uri.query = URI.encode_www_form(params)
req = Net::HTTP::Get.new(uri)

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(req)
end
res = Faraday.get(uri)

Response.new(res)
end
Expand Down
8 changes: 1 addition & 7 deletions lib/postnord/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ module Postnord
class Response
def initialize(data)
@data = data
@code = data.code
@status = data.msg
@code = data.status
end

def code
@data.code
end

def status
@data.status
end

def data
JSON.parse(@data.body)
rescue JSON::ParserError
Expand All @@ -23,7 +18,6 @@ def data
def to_h
{
code: @code,
status: @status,
data: data,
}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/postnord/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Postnord
VERSION = "0.2.3"
VERSION = "0.3.0"
end
1 change: 1 addition & 0 deletions postnord.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency 'faraday'
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", ">= 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
Expand Down

0 comments on commit b0c7bde

Please sign in to comment.