everwrite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +24 -0
- data/TODO +5 -0
- data/lib/everwrite.rb +129 -0
- metadata +167 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Everwrite
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
= Everwrite API
|
2
|
+
|
3
|
+
Everwrite gem for API access.
|
4
|
+
|
5
|
+
== Usage of Everwrite API
|
6
|
+
|
7
|
+
* Get terms suggestion
|
8
|
+
|
9
|
+
Everwrite.api_key = "1234567890abcde"
|
10
|
+
@everapi = Everwrite.new :domain => 'yourdormain.com', :language =>'en'
|
11
|
+
@everapi.get_terms_suggestion "love"
|
12
|
+
|
13
|
+
* Get keyword suggestion for texts
|
14
|
+
|
15
|
+
Everwrite.api_key = "1234567890abcde"
|
16
|
+
@everapi = Everwrite.new :domain => 'yourdormain.com', :language =>'en'
|
17
|
+
@everapi.get_keyword_suggestion_for_text title: "how to make hot chocolate", content: "chocholate is associated with ..."
|
18
|
+
|
19
|
+
|
20
|
+
== Copyright
|
21
|
+
|
22
|
+
Copyright (c) 2013 Everwrite. See LICENSE.txt for
|
23
|
+
further details.
|
24
|
+
|
data/TODO
ADDED
data/lib/everwrite.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Everwrite
|
5
|
+
VERSION = "0.0.1"
|
6
|
+
|
7
|
+
# Public: Set the API key.
|
8
|
+
#
|
9
|
+
# value - The String API key.
|
10
|
+
#
|
11
|
+
# Examples
|
12
|
+
#
|
13
|
+
# EverApi.api_key = '123456'
|
14
|
+
# # => '123456'
|
15
|
+
def self.api_key=(value)
|
16
|
+
@@api_key = value
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: Initialize an API instance.
|
20
|
+
#
|
21
|
+
# opts - The Hash of options (default {}):
|
22
|
+
# :domain - The String domain.
|
23
|
+
def initialize(opts = {})
|
24
|
+
@domain = opts[:domain]
|
25
|
+
@language = opts[:language]
|
26
|
+
@root_url = "http://api.everwrite.com/v1/"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public: Query the API about given words.
|
30
|
+
#
|
31
|
+
# query - The String query to lookup.
|
32
|
+
# page - Pagination index.
|
33
|
+
#
|
34
|
+
# Examples
|
35
|
+
#
|
36
|
+
# EverAPI.get_terms_suggestion 'Ruby on Rails'
|
37
|
+
# # => [{"name": "ruby on rails web framework", "score": 3.123123132, "everank": 3.3333, ...},...]
|
38
|
+
#
|
39
|
+
# Returns an Array of Hash objects with suggestion of terms.
|
40
|
+
def get_terms_suggestion(query, page = 1)
|
41
|
+
response = Net::HTTP.get assemble_url_terms_suggestion query, page
|
42
|
+
@results = JSON.parse response
|
43
|
+
end
|
44
|
+
|
45
|
+
# Public: Query the API about given title and content.
|
46
|
+
#
|
47
|
+
# title - The title of the text.
|
48
|
+
# content - The content of the text.
|
49
|
+
# page - Pagination index.
|
50
|
+
#
|
51
|
+
# Examples
|
52
|
+
#
|
53
|
+
# EverAPI.get_keyword_suggestion_for_text title: 'Ruby on Rails', content: 'Ruby on Rails is an open-source web framework'
|
54
|
+
# # => [{"name": "ruby on rails open-source", "score": 4.123123132, "everank": 4.3333, ...},...]
|
55
|
+
#
|
56
|
+
# Returns an Array of Hash objects with suggestion of terms for the text.
|
57
|
+
def get_keyword_suggestion_for_text(params = {}, page = 1)
|
58
|
+
title = params[:title]
|
59
|
+
content = params[:content]
|
60
|
+
url = URI.join @root_url, 'text/keywords/suggestions/'
|
61
|
+
data = assemble_post_data_to_keyword_suggestion title, content, page
|
62
|
+
response = Net::HTTP.post_form url, data
|
63
|
+
JSON.parse(response.body)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# Private: Assemble search URL for terms suggestion.
|
69
|
+
#
|
70
|
+
# query - The String query to lookup.
|
71
|
+
# page - Pagination index.
|
72
|
+
#
|
73
|
+
# Examples
|
74
|
+
#
|
75
|
+
# EverAPI.assemble_url_terms_suggestion 'Ruby on Rails'
|
76
|
+
# # => #<URI URL:http://api.everwrite.com/api/:v/keywords/suggestions?domain=domain.com&api_key=123456&q=Ruby%20on%20Rails>
|
77
|
+
#
|
78
|
+
# Returns the URI search URL.
|
79
|
+
def assemble_url_terms_suggestion(query, page)
|
80
|
+
url = URI.join @root_url, 'keywords/suggestions'
|
81
|
+
url.query = URI.encode_www_form domain: @domain, api_key: @@api_key, q: query, lang: @language, page: page
|
82
|
+
url
|
83
|
+
end
|
84
|
+
|
85
|
+
# Private: Assemble URL POST data URL for keyword suggestion.
|
86
|
+
#
|
87
|
+
# title - The title of the text.
|
88
|
+
# content - The content of the text.
|
89
|
+
# page - Pagination index.
|
90
|
+
#
|
91
|
+
# Returns the POST data.
|
92
|
+
def assemble_post_data_to_keyword_suggestion(title, content, page)
|
93
|
+
data = {"domain" => @domain, "api_key" => @@api_key,
|
94
|
+
"title" => title, "content" => content,
|
95
|
+
"lang" => @language, "page" => page}
|
96
|
+
end
|
97
|
+
|
98
|
+
# Private: Assemble search URL for keyword suggestion for a text.
|
99
|
+
#
|
100
|
+
# title - The title of the text.
|
101
|
+
# content - The content of the text.
|
102
|
+
# page - Pagination index.
|
103
|
+
#
|
104
|
+
# Examples
|
105
|
+
#
|
106
|
+
# EverAPI.assemble_url_keyword_suggestion_for_text 'Ruby on Rails', 'Ruby on Rails is an open-source web framework'
|
107
|
+
# # => #<URI URL:http://api.everwrite.com/:v/text/keywords/suggestions?domain=domain.com&api_key=123456&title=Ruby%20on%20Rails&content=Ruby%20on%20Rails%20is%20an%20open-source%20web%20framework>
|
108
|
+
#
|
109
|
+
# Returns the URI search URL.
|
110
|
+
def assemble_url_keyword_suggestion_for_text(title, content, page)
|
111
|
+
url = URI.join @root_url, 'text/keywords/suggestions'
|
112
|
+
url.query = URI.encode_www_form domain: @domain, api_key: @@api_key, title: title, content: content, lang: @language, page: page
|
113
|
+
url
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
# quick test
|
119
|
+
if __FILE__ == $PROGRAM_NAME
|
120
|
+
Everwrite.api_key = "1234567890abcde"
|
121
|
+
@everapi = Everwrite.new :domain => 'yourdormain.com', :language =>'en'
|
122
|
+
|
123
|
+
result = @everapi.get_terms_suggestion "love"
|
124
|
+
p result
|
125
|
+
|
126
|
+
result = @everapi.get_keyword_suggestion_for_text title: "how to make hot chocolate", content: "chocolate is associated with ..."
|
127
|
+
p result
|
128
|
+
end
|
129
|
+
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: everwrite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lucas Arruda
|
9
|
+
- Edmar Ferreira
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rdoc
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '3.12'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.12'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.2
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.2.2
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: jeweler
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.8.4
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.8.4
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: simplecov
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 0.7.1
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.7.1
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: json
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
description: verwrite API gem
|
128
|
+
email: edmar@everwrite.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files:
|
132
|
+
- LICENSE.txt
|
133
|
+
- README.rdoc
|
134
|
+
- TODO
|
135
|
+
files:
|
136
|
+
- lib/everwrite.rb
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.rdoc
|
139
|
+
- TODO
|
140
|
+
homepage: http://github.com/everwrite/gem
|
141
|
+
licenses: []
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
hash: -486883497917090170
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 1.8.24
|
164
|
+
signing_key:
|
165
|
+
specification_version: 3
|
166
|
+
summary: Everwrite API
|
167
|
+
test_files: []
|