Class: Berrycrawl::Brand::Client
- Inherits:
-
Object
- Object
- Berrycrawl::Brand::Client
- Defined in:
- lib/Berrycrawl/brand/client.rb
Instance Method Summary collapse
- #initialize(client:) ⇒ void constructor
-
#retrieve(request_options: {}, **params) ⇒ Berrycrawl::Types::BrandResponse
Send one website URL.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/Berrycrawl/brand/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#retrieve(request_options: {}, **params) ⇒ Berrycrawl::Types::BrandResponse
Send one website URL. BerryCrawl returns the brand identity found on that site.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/Berrycrawl/brand/client.rb', line 24 def retrieve(request_options: {}, **params) params = Berrycrawl::Internal::Types::Utils.normalize_keys(params) request = Berrycrawl::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "brand", body: Berrycrawl::Brand::Types::BrandDto.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Berrycrawl::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Berrycrawl::Types::BrandResponse.load(response.body) else error_class = Berrycrawl::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |