Skip to content

Commit

Permalink
Merge pull request #3 from rodolfobandeira/add-unique-entry-point-for…
Browse files Browse the repository at this point in the history
…-requests

Refactor requests logic
  • Loading branch information
rodolfobandeira authored Aug 22, 2018
2 parents a758d40 + 9e30cf4 commit 6dead76
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 39 deletions.
9 changes: 5 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-08-21 20:52:04 -0400 using RuboCop version 0.51.0.
# on 2018-08-21 21:48:44 -0400 using RuboCop version 0.51.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -22,16 +22,17 @@ Metrics/BlockLength:
Metrics/LineLength:
Max: 247

# Offense count: 2
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 12
Max: 11

# Offense count: 3
# Offense count: 4
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/spacex/base_request.rb'
- 'lib/spacex/company_info.rb'
- 'lib/spacex/launches.rb'
- 'lib/spacex/version.rb'
1 change: 1 addition & 0 deletions lib/spacex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'faraday_middleware/response_middleware'
require 'hashie'

require_relative 'spacex/base_request'
require_relative 'spacex/version'
require_relative 'spacex/launches'
require_relative 'spacex/company_info'
19 changes: 19 additions & 0 deletions lib/spacex/base_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module SPACEX
module BaseRequest
def self.get(path)
data = Faraday.new(
url: "#{SPACEX::ROOT_URI}/#{path}",
request: {
params_encoder: Faraday::FlatParamsEncoder
}
) do |c|
c.use ::FaradayMiddleware::ParseJson
c.use Faraday::Response::RaiseError
c.use Faraday::Adapter::NetHttp
end
Hashie::Mash.new(data.get.body)
end
end
end
18 changes: 1 addition & 17 deletions lib/spacex/company_info.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
# frozen_string_literal: true

require 'ostruct'

module SPACEX
module CompanyInfo
ROOT_URI = 'https://api.spacexdata.com/v2'

def self.info
path = 'info'

data = Faraday.new(
url: "#{ROOT_URI}/#{path}",
request: {
params_encoder: Faraday::FlatParamsEncoder
}
) do |c|
c.use ::FaradayMiddleware::ParseJson
c.use Faraday::Response::RaiseError
c.use Faraday::Adapter::NetHttp
end
Hashie::Mash.new(data.get.body)
SPACEX::BaseRequest.get('info')
end
end
end
18 changes: 1 addition & 17 deletions lib/spacex/launches.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
# frozen_string_literal: true

require 'ostruct'

module SPACEX
module Launches
ROOT_URI = 'https://api.spacexdata.com/v2'

def self.latest
path = 'launches/latest'

data = Faraday.new(
url: "#{ROOT_URI}/#{path}",
request: {
params_encoder: Faraday::FlatParamsEncoder
}
) do |c|
c.use ::FaradayMiddleware::ParseJson
c.use Faraday::Response::RaiseError
c.use Faraday::Adapter::NetHttp
end
Hashie::Mash.new(data.get.body)
SPACEX::BaseRequest.get('launches/latest')
end
end
end
3 changes: 2 additions & 1 deletion lib/spacex/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

module SPACEX
VERSION = '0.0.4'
VERSION = '0.0.5'
ROOT_URI = 'https://api.spacexdata.com/v2'

def self.help
puts 'https://github.com/rodolfobandeira/spacex'
Expand Down

0 comments on commit 6dead76

Please sign in to comment.