Sha256: 974de653297a28457f319b29af3dac01ac13a709e05153fffbdb7846755be52b

Contents?: true

Size: 965 Bytes

Versions: 16

Compression:

Stored size: 965 Bytes

Contents

require 'http'
require 'json'

url = 'http://api.wordnik.com:80/v4/words.json/randomWords'

json_return = HTTP.get(
  url, 
  :params => { 
    :hasDictionaryDef => true,  
    :includePartOfSpeech => 'noun-plural', 
    :minCorpusCount => 10, 
    :maxCorpusCount => -1, 
    :minDictionaryCount => 1,
    :maxDictionaryCount => -1,
    :minLength => 5,
    :maxLength => 12,
    :sortBy => 'alpha',
    :sortOrder => 'asc',
    :limit => 10,
    :api_key => '63f5001dfacf2d619230e08591702875786da258b471becb6'
  }
)

if json_return
  json_data = JSON.parse(json_return.to_s)
  
  if json_data.include?("type") && json_data.include?("message")
    puts "wordnik error: #{json_data["message"]}"
  else
    word_list = []
    json_data.map {|j| word_list.push(j["word"])}
    if word_list.length > 0
      p word_list
    else
      puts 'no words received'
    end
  end
else
  puts "json error: #{json_return.to_s}"
end


Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
gemwarrior-0.15.20 tests/json_api_call.rb
gemwarrior-0.15.19 tests/json_api_call.rb
gemwarrior-0.15.18 tests/json_api_call.rb
gemwarrior-0.15.17 tests/json_api_call.rb
gemwarrior-0.15.16 tests/json_api_call.rb
gemwarrior-0.15.15 tests/json_api_call.rb
gemwarrior-0.15.14 tests/json_api_call.rb
gemwarrior-0.15.13 tests/json_api_call.rb
gemwarrior-0.15.12 tests/json_api_call.rb
gemwarrior-0.15.11 tests/json_api_call.rb
gemwarrior-0.15.10 tests/json_api_call.rb
gemwarrior-0.15.9 tests/json_api_call.rb
gemwarrior-0.15.8 tests/json_api_call.rb
gemwarrior-0.15.7 tests/json_api_call.rb
gemwarrior-0.15.6 tests/json_api_call.rb
gemwarrior-0.15.5 tests/json_api_call.rb