Module: Serpbook

Includes:
HTTParty
Defined in:
lib/serpbook.rb,
lib/serpbook/version.rb,
lib/serpbook/category.rb

Defined Under Namespace

Classes: Category, Configuration

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.categoriesObject



25
26
27
28
29
# File 'lib/serpbook.rb', line 25

def categories
 request(viewkey: 'getcategories').map do |name, url|
    [name, CGI::parse(URI.parse(url).query).map{|k,v| [k.to_sym, v.first]}.to_h]
  end.to_h
end

.config {|configuration| ... } ⇒ Object

Yields:



17
18
19
# File 'lib/serpbook.rb', line 17

def config &block
  yield(configuration)
end

.configurationObject



21
22
23
# File 'lib/serpbook.rb', line 21

def configuration
  @configuration ||= Configuration.new
end

.request(params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/serpbook.rb', line 31

def request(params)
  full_params = default_params.merge(params)
  response = self.get('/', query: full_params, verify: false)

  if response.code != 200
    raise ResponseError, "responded with #{response.code}, and messsage #{response.body}"
  end

  JSON.parse(response.body)
end