Class: Hark::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/hark/api.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configurationObject

The configuration object.

See Also:



54
55
56
# File 'lib/hark/api.rb', line 54

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.apiObject

The api object.

Raises:

  • (ArgumentError)

See Also:



60
61
62
63
# File 'lib/hark/api.rb', line 60

def api
  raise ArgumentError if configuration.api_key.blank?
  @api
end

.clip(clip_id) ⇒ Object

Queries the API for the clip JSON.

See Also:



67
68
69
# File 'lib/hark/api.rb', line 67

def clip(clip_id)
  api.clip(clip_id)
end

.configure {|configuration| ... } ⇒ Object

Call this method to configure the library at runtime.

Examples:

Hark::API.configure do |config|
  config.api_key = '1234567890abcdef'
end

Yields:



47
48
49
50
# File 'lib/hark/api.rb', line 47

def configure
  yield(configuration)
  @api ||= API.new
end

.search(search_term) ⇒ Object

Queries the API for the search term

See Also:



73
74
75
# File 'lib/hark/api.rb', line 73

def search(search_term)
  api.search(search_term)
end

Instance Method Details

#clip(clip_id) ⇒ String

Queries the API for the clip JSON

Parameters:

  • clip_id (String)

    The clip identifier

Returns:

  • (String)

    Returns a JSON representation of the clip.



15
16
17
# File 'lib/hark/api.rb', line 15

def clip( clip_id )
  self.class.get("/clips/#{clip_id}.json", options)
end

#optionsHash

Default options passed back to in a HTTParty call.

Returns:

  • (Hash)

    Returns hash of options for a HTTParty call.



31
32
33
# File 'lib/hark/api.rb', line 31

def options
  { :headers => { 'X-HarkToken' => self.class.configuration.api_key } }
end

#search(search_term) ⇒ String

Queries the API for the search term

Parameters:

  • search_term (String)

    The clip identifier

Returns:

  • (String)

    Returns a JSON array of clips



22
23
24
25
26
27
# File 'lib/hark/api.rb', line 22

def search(search_term)
  search_options = options
  search_options[:query] = { 'keywords' => search_term }
  puts search_options
  self.class.get("/clips/search.json", search_options)
end