Class: Cliptic::Main::Fetch::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/cliptic/main.rb

Direct Known Subclasses

Cache

Constant Summary collapse

URL =
"https://data.puzzlexperts.com/puzzleapp-v3/data.php"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date: Date.today, psid: 100000160) ⇒ Request

Returns a new instance of Request.



136
137
138
# File 'lib/cliptic/main.rb', line 136

def initialize(date:Date.today, psid:100000160)
  @data = {date:date, psid:psid}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



135
136
137
# File 'lib/cliptic/main.rb', line 135

def data
  @data
end

Instance Method Details

#rawObject



146
147
148
149
150
# File 'lib/cliptic/main.rb', line 146

def raw
  @raw || Curl.get(URL, data) do |curl|
    curl.ssl_verify_peer = false
  end.body
end

#send_requestObject



139
140
141
# File 'lib/cliptic/main.rb', line 139

def send_request
  valid_input? ? raw : (raise Cliptic::Errors::Invalid_Date.new(data[:date]))
end

#valid_input?Boolean

Returns:

  • (Boolean)


142
143
144
145
# File 'lib/cliptic/main.rb', line 142

def valid_input?
  JSON.parse(raw, symbolize_names:true)
    .dig(:cells, 0, :meta, :data).length > 0
end