Class: CatFactsApiClient::CatFact
- Inherits:
-
Object
- Object
- CatFactsApiClient::CatFact
- Defined in:
- lib/cat_facts_api_client/cat_fact.rb
Constant Summary collapse
- API_URL =
'https://catfact.ninja/fact'.freeze
- LENGTH_THRESHOLD =
60
Instance Attribute Summary collapse
-
#facts_json ⇒ Object
readonly
Returns the value of attribute facts_json.
Class Method Summary collapse
Instance Attribute Details
#facts_json ⇒ Object (readonly)
Returns the value of attribute facts_json.
7 8 9 |
# File 'lib/cat_facts_api_client/cat_fact.rb', line 7 def facts_json @facts_json end |
Class Method Details
.get ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/cat_facts_api_client/cat_fact.rb', line 12 def self.get facts = HTTParty.get(API_URL).body response = JSON.parse(facts) { text: response['fact'], tag: response['length'] > LENGTH_THRESHOLD ? 'large' : 'short' } end |