Class: TWM::Sightings

Inherits:
Object
  • Object
show all
Defined in:
lib/twm-ruby/api.rb

Overview

The Whale Hotline API hotline.whalemuseum.org/api

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ Sightings

Returns a new instance of Sightings.



9
10
11
12
# File 'lib/twm-ruby/api.rb', line 9

def initialize(api)
  @api = api
  @api.create_session('http://hotline.whalemuseum.org')
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



7
8
9
# File 'lib/twm-ruby/api.rb', line 7

def api
  @api
end

Instance Method Details

#count(params = {}) ⇒ Integer

Retrieve Hotline sighting reports

Examples:


count = twm.sightings.count
=> 17000

count = twm.sightings.count(species: 'orca')

Parameters:

  • params (Hash) (defaults to: {})

    Optional params or filters:

Options Hash (params):

  • species (String)

    Get sighting reports for a species.

  • orca_type (String)

    Get sighting reports for a type of orca.

  • orca_pod (String)

    Get sighting reports for a pod of orca.

  • since (String)

    Get sighting reports after this date.

  • until (String)

    Get sighting reports before this date.

  • near (String)

    Get sighting reports near a Lat/Lng point.

  • radius (String)

    Get sighting reports within this distance of center point.

Returns:

  • (Integer)

    The count of sighting reports.

See Also:



36
37
38
# File 'lib/twm-ruby/api.rb', line 36

def count(params = {})
  @api.get("api/count.json", params)
end

#find(id) ⇒ JSON

Retrieve a specific sighting report

Examples:


sighting = twm.sightings.find('52b158c0686f7438d8ac0600')
sighting['species']
=> "orca"

Parameters:

  • id (String)

    The ID of the sighting report to retrieve.

Returns:

  • (JSON)

    A sighting report object.

See Also:



54
55
56
# File 'lib/twm-ruby/api.rb', line 54

def find(id)
  @api.get("api/#{id.to_s}.json")
end

#search(params = {}) ⇒ JSON

Retrieve Hotline sighting reports

Examples:


sightings = twm.sightings.search
sightings.size
=> 17000

sightings = twm.sightings.search(species: 'orca', limit: 250)

Parameters:

  • params (Hash) (defaults to: {})

    Optional params or filters:

Options Hash (params):

  • species (String)

    Get sighting reports for a species.

  • orca_type (String)

    Get sighting reports for a type of orca.

  • orca_pod (String)

    Get sighting reports for a pod of orca.

  • limit (Integer)

    The number of sighting reports to return.

  • page (Integer)

    The page number to return.

  • since (String)

    Get sighting reports after this date.

  • until (String)

    Get sighting reports before this date.

  • near (String)

    Get sighting reports near a Lat/Lng point.

  • radius (String)

    Get sighting reports within this distance of center point.

Returns:

  • (JSON)

    An array of matching sighting reports.

See Also:



83
84
85
# File 'lib/twm-ruby/api.rb', line 83

def search(params = {})
  @api.get("api.json", params)
end