Commit 4aa4ab50 authored by Sergey Gernyak's avatar Sergey Gernyak

REFACTOR: extract ListBase and SingleBase for Parsers

parent ea3face8
......@@ -105,6 +105,8 @@ module BetfairApiNgRails
module Parsers
autoload :Base, 'betfair_api_ng_rails/api/parsers/base'
autoload :ListBase, 'betfair_api_ng_rails/api/parsers/list_base'
autoload :SingleBase, 'betfair_api_ng_rails/api/parsers/single_base'
autoload :ListCompetitions, 'betfair_api_ng_rails/api/parsers/list_competitions'
autoload :ListEventTypes, 'betfair_api_ng_rails/api/parsers/list_event_types'
autoload :ListEvents, 'betfair_api_ng_rails/api/parsers/list_events'
......
......@@ -8,14 +8,13 @@ module BetfairApiNgRails
:id,
:name
]
attributes COMPETITION_ATTRS
def self.to_hash_attrs
COMPETITION_ATTRS
end
end
end
end
end
\ No newline at end of file
end
......@@ -2,7 +2,6 @@ module BetfairApiNgRails
module Api
module Data
class CompetitionResult < Api::Data::Base
COMPETITION_RESULT_ATTRS = [
:market_count,
:competition_region,
......@@ -10,8 +9,7 @@ module BetfairApiNgRails
]
attributes COMPETITION_RESULT_ATTRS
end
end
end
end
\ No newline at end of file
end
......@@ -2,10 +2,8 @@ module BetfairApiNgRails
module Api
module Data
module Constants
ATTRS_AS_IS = [Hash, String, Symbol, Fixnum, NilClass]
end
end
end
end
\ No newline at end of file
end
......@@ -2,15 +2,13 @@ module BetfairApiNgRails
module Api
module Data
class CountryCodeResult < Api::Data::Base
COUNTRY_CODE_RESULT_ATTRS = [
:market_count,
:country_code
]
attributes COUNTRY_CODE_RESULT_ATTRS
end
end
end
end
\ No newline at end of file
end
......@@ -18,8 +18,7 @@ module BetfairApiNgRails
def self.to_hash_attrs
EVENT_ATTRS
end
end
end
end
end
\ No newline at end of file
end
......@@ -2,15 +2,13 @@ module BetfairApiNgRails
module Api
module Data
class EventResult < Api::Data::Base
EVENT_RESULT_ATTRS = [
:market_count,
{event: { type: BetfairApiNgRails::Event }}
]
attributes EVENT_RESULT_ATTRS
end
end
end
end
\ No newline at end of file
end
......@@ -2,7 +2,6 @@ module BetfairApiNgRails
module Api
module Data
class Order < Api::Data::Base
ORDER_ATTRS = [
:bet_id,
:order_type,
......@@ -22,8 +21,7 @@ module BetfairApiNgRails
]
attributes ORDER_ATTRS
end
end
end
end
\ No newline at end of file
end
......@@ -2,7 +2,6 @@ module BetfairApiNgRails
module Api
module Parsers
class Base
attr_reader :responser
def initialize(responser)
......@@ -10,20 +9,27 @@ module BetfairApiNgRails
end
def process
fetch_result_json.map { |json_row| process_row json_row }
raise 'Must be reimplemented!'
end
private
private
def fetch_result_json
responser.has_error? ? [] : responser.api_result
responser.has_error? ? default_value : responser.api_result
end
def process_row(json_row)
def default_value
raise 'Must be reimplemented!'
end
def process_row(json_row)
data_class.from_json json_row
end
def data_class
raise 'Must be reimplemented!'
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class ListBase < Api::Parsers::Base
def process
fetch_result_json.map { |json_row| process_row json_row }
end
private
def default_value
[]
end
end
end
end
end
module BetfairApiNgRails
module Api
module Parsers
class ListCompetitions < Api::Parsers::Base
class ListCompetitions < Api::Parsers::ListBase
private
private
def process_row(json_row)
Api::Data::CompetitionResult.from_json json_row
def data_class
Api::Data::CompetitionResult
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class ListCountries < Api::Parsers::Base
class ListCountries < Api::Parsers::ListBase
private
private
def process_row(json_row)
Api::Data::CountryCodeResult.from_json json_row
def data_class
Api::Data::CountryCodeResult
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class ListEventTypes < Api::Parsers::Base
class ListEventTypes < Api::Parsers::ListBase
private
private
def process_row(json_row)
Api::Data::EventTypeResult.from_json json_row
def data_class
Api::Data::EventTypeResult
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class ListEvents < Api::Parsers::Base
class ListEvents < Api::Parsers::ListBase
private
private
def process_row(json_row)
Api::Data::EventResult.from_json json_row
def data_class
Api::Data::EventResult
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class ListMarketBook < Api::Parsers::Base
class ListMarketBook < Api::Parsers::ListBase
private
private
def process_row(json_row)
BetfairApiNgRails::MarketBook.from_json json_row
def data_class
BetfairApiNgRails::MarketBook
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class ListMarketCatalogue < Api::Parsers::Base
class ListMarketCatalogue < Api::Parsers::ListBase
private
private
def process_row(json_row)
BetfairApiNgRails::MarketCatalogue.from_json json_row
def data_class
BetfairApiNgRails::MarketCatalogue
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class ListMarketTypes < Api::Parsers::Base
class ListMarketTypes < Api::Parsers::ListBase
private
private
def process_row(json_row)
Api::Data::MarketTypeResult.from_json json_row
def data_class
Api::Data::MarketTypeResult
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class ListTimeRanges < Api::Parsers::Base
class ListTimeRanges < Api::Parsers::ListBase
private
private
def process_row(json_row)
Api::Data::TimeRangeResult.from_json json_row
def data_class
Api::Data::TimeRangeResult
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class ListVenues < Api::Parsers::Base
class ListVenues < Api::Parsers::ListBase
private
private
def process_row(json_row)
Api::Data::VenueResult.from_json json_row
def data_class
Api::Data::VenueResult
end
end
end
end
end
\ No newline at end of file
end
module BetfairApiNgRails
module Api
module Parsers
class SingleBase
def process
process_row fetch_result_json
end
private
def default_value
"{}"
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment