Class: WordsApi::APIsController

Inherits:
BaseController show all
Defined in:
lib/words_api/controllers/ap_is_controller.rb

Overview

APIsController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent

Constructor Details

This class inherits a constructor from WordsApi::BaseController

Instance Method Details

#definitions(word) ⇒ DefinitionsResponse

Get definitions of a word, including the part of speech. definitions for.

Parameters:

  • word (String)

    Required parameter: The word to search the

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/words_api/controllers/ap_is_controller.rb', line 32

def definitions(word)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/words/{word}/definitions',
                                 Server::DEFAULT)
               .template_param(new_parameter(word, key: 'word')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('RapidAPI-Key')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(DefinitionsResponse.method(:from_hash)))
    .execute
end

#examples(word) ⇒ ExamplesResponse

Get examples of how the word is used. for.

Parameters:

  • word (String)

    Required parameter: The word to search the examples

Returns:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/words_api/controllers/ap_is_controller.rb', line 95

def examples(word)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/words/{word}/examples',
                                 Server::DEFAULT)
               .template_param(new_parameter(word, key: 'word')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('RapidAPI-Key')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ExamplesResponse.method(:from_hash)))
    .execute
end

#frequency(word) ⇒ FrequencyResponse

Expands upon the frequency score returned by the main /words/#word endpoint. Returns zipf, a score indicating how common the word is in the English language, with a range of 1 to 7; per Million, the number of times the word is likely to appear in a corpus of one million English words; and diversity, a 0-1 scale the shows the likelihood of the word appearing in an English document that is part of a corpus. for.

Parameters:

  • word (String)

    Required parameter: The word to search frequency

Returns:



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/words_api/controllers/ap_is_controller.rb', line 119

def frequency(word)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/words/{word}/frequency',
                                 Server::DEFAULT)
               .template_param(new_parameter(word, key: 'word')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('RapidAPI-Key')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(FrequencyResponse.method(:from_hash)))
    .execute
end

#pronunciation(word) ⇒ PronunciationResponse

How to pronounce a word, according to the International Phonetic Alphabet. May include multiple results if the word is pronounced differently depending on its part of speech. for.

Parameters:

  • word (String)

    Required parameter: The word to search pronunciation

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/words_api/controllers/ap_is_controller.rb', line 53

def pronunciation(word)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/words/{word}/pronunciation',
                                 Server::DEFAULT)
               .template_param(new_parameter(word, key: 'word')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('RapidAPI-Key')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(PronunciationResponse.method(:from_hash)))
    .execute
end

#synonyms(word) ⇒ SynonymsResponse

Get synonyms of a word. for.

Parameters:

  • word (String)

    Required parameter: The word to search synonyms

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/words_api/controllers/ap_is_controller.rb', line 13

def synonyms(word)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/words/{word}/synonyms',
                                 Server::DEFAULT)
               .template_param(new_parameter(word, key: 'word')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('RapidAPI-Key')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SynonymsResponse.method(:from_hash)))
    .execute
end

#word(word) ⇒ WordResponse

Retrieve information about a word. Results can include definitions, part of speech, synonyms, related words, syllables, and pronunciation. This method is useful to see which relationships are attached to which definition and part of speech of a word. is used to provide the word, about which the information is being fetched.

Parameters:

  • word (String)

    Required parameter: This is a template parameter that

Returns:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/words_api/controllers/ap_is_controller.rb', line 76

def word(word)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/words/{word}',
                                 Server::DEFAULT)
               .template_param(new_parameter(word, key: 'word')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('RapidAPI-Key')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(WordResponse.method(:from_hash)))
    .execute
end