Sha256: bafa72e20068ce77858f0787ef97c89f21f8ac93950734fedf61ddda000133df

Contents?: true

Size: 890 Bytes

Versions: 30

Compression:

Stored size: 890 Bytes

Contents

require 'httparty'
require 'zoo_app/models/alligator'

module ZooApp
  class AnimalServiceClient

    include HTTParty
    base_uri 'animal-service.com'

    def self.find_alligators
      response = get("/alligators", :headers => {'Accept' => 'application/json'})
      if response.success?
        parse_body(response).collect do | hash |
          ZooApp::Animals::Alligator.new(hash)
        end
      else
        raise response.body
      end
    end

    def self.find_alligator_by_name name
      response = get("/alligators/#{name}", :headers => {'Accept' => 'application/json'})
      if response.success?
        ZooApp::Animals::Alligator.new(parse_body(response))
      elsif response.code == 404
        nil
      else
        raise response.body
      end
    end

    def self.parse_body response
      JSON.parse(response.body, {:symbolize_names => true})
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
pact-1.0.30 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.29 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.28 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.27 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.26 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.25 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.24 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.23 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.22 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.21 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.20 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.19 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.18 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.15 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.13 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.12 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.11 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.10 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.9 example/zoo-app/lib/zoo_app/animal_service_client.rb
pact-1.0.8 example/zoo-app/lib/zoo_app/animal_service_client.rb