Class: Quintype::API::Client
- Inherits:
- 
      Object
      
        - Object
- Quintype::API::Client
 
- Defined in:
- lib/quintype/api/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_config ⇒ Object
- #get_story_by_slug(slug) ⇒ Object
- 
  
    
      #initialize(conn)  ⇒ Client 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Client. 
- #post_bulk(requests) ⇒ Object
Constructor Details
#initialize(conn) ⇒ Client
Returns a new instance of Client.
| 27 28 29 | # File 'lib/quintype/api/client.rb', line 27 def initialize(conn) @conn = conn end | 
Class Method Details
.establish_connection(host, adapter = nil) ⇒ Object
| 13 14 15 16 17 18 19 20 | # File 'lib/quintype/api/client.rb', line 13 def establish_connection(host, adapter = nil) connection = Faraday.new(host) do |conn| conn.request :json conn.response :json, :content_type => /\bjson$/ conn.adapter(adapter || Faraday.default_adapter) end @client = new(connection) end | 
.instance ⇒ Object
| 22 23 24 | # File 'lib/quintype/api/client.rb', line 22 def instance @client end | 
Instance Method Details
#get_config ⇒ Object
| 31 32 33 34 35 | # File 'lib/quintype/api/client.rb', line 31 def get_config response = get("/api/v1/config") raise ClientException.new("Could not get config", response) unless response.status == 200 response.body end | 
#get_story_by_slug(slug) ⇒ Object
| 37 38 39 40 41 42 | # File 'lib/quintype/api/client.rb', line 37 def get_story_by_slug(slug) response = get("/api/v1/stories-by-slug", slug: slug) return nil if response.status == 404 raise ClientException.new("Could not fetch story", response) unless response.status == 200 response.body["story"] end | 
#post_bulk(requests) ⇒ Object
| 44 45 46 47 48 | # File 'lib/quintype/api/client.rb', line 44 def post_bulk(requests) response = post("/api/v1/bulk", requests: requests) raise ClientException.new("Could not bulk fetch", response) unless response.status == 200 response.body["results"] end |