Class: Everwrite

Inherits:
Object
  • Object
show all
Defined in:
lib/everwrite.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Everwrite

Public: Initialize an API instance.

opts - The Hash of options (default {}):

:domain - The String domain.


23
24
25
26
27
# File 'lib/everwrite.rb', line 23

def initialize(opts = {})
  @domain   = opts[:domain]
  @language = opts[:language]
  @root_url = "http://api.everwrite.com/v1/"
end

Class Method Details

.api_key=(value) ⇒ Object

Public: Set the API key.

value - The String API key.

Examples

EverApi.api_key = '123456'
# => '123456'


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

def self.api_key=(value)
  @@api_key = value
end

Instance Method Details

#get_keyword_suggestion_for_text(params = {}, page = 1) ⇒ Object

Public: Query the API about given title and content.

title - The title of the text. content - The content of the text. page - Pagination index.

Examples

EverAPI.get_keyword_suggestion_for_text title: 'Ruby on Rails', content: 'Ruby on Rails is an open-source web framework'
# => [{"name": "ruby on rails open-source", "score": 4.123123132, "everank": 4.3333, ...},...]

Returns an Array of Hash objects with suggestion of terms for the text.



57
58
59
60
61
62
63
64
# File 'lib/everwrite.rb', line 57

def get_keyword_suggestion_for_text(params = {}, page = 1)
  title = params[:title]
  content = params[:content]
  url = URI.join @root_url, 'text/keywords/suggestions/'
  data = assemble_post_data_to_keyword_suggestion title, content, page
  response = Net::HTTP.post_form url, data
  JSON.parse(response.body)
end

#get_terms_suggestion(query, page = 1) ⇒ Object

Public: Query the API about given words.

query - The String query to lookup. page - Pagination index.

Examples

EverAPI.get_terms_suggestion 'Ruby on Rails'
# => [{"name": "ruby on rails web framework", "score": 3.123123132, "everank": 3.3333, ...},...]

Returns an Array of Hash objects with suggestion of terms.



40
41
42
43
# File 'lib/everwrite.rb', line 40

def get_terms_suggestion(query, page = 1)
  response = Net::HTTP.get assemble_url_terms_suggestion query, page
  @results = JSON.parse response
end