wikipedia_rest_client 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +14 -0
- data/lib/wikipedia_rest_client/page.rb +1 -1
- data/lib/wikipedia_rest_client/utils.rb +3 -1
- data/lib/wikipedia_rest_client/version.rb +1 -1
- data/lib/wikipedia_rest_client.rb +25 -7
- metadata +2 -3
- data/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b89100e886679d030ac8ea076c33288bc0d6191f629c30895fcea314aba699b7
|
4
|
+
data.tar.gz: 26bc7f8adfabe4138e7a19cfd1ee29566285c1f5eb3efbe9ea7f7a9c279684bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cfcdf869e16557ce31eb7ef36ec428ef77b8cc57fdad278d58da25838dae200196bd4870c8cd2ced62e57004b3e076b47d00fc12d01d5246378383f0a8e8d11
|
7
|
+
data.tar.gz: 85434dde0c555705a6dfa0ec8e10c40e6b7ab3ed32cf29a8ade343329ffaa1b92450d8550c4b69620787c77042a1b25cae3c75d2a1b294a54b6b028bf4122fb1
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -40,6 +40,17 @@ WikipediaRestClient.setUserAgent(< Email addresses or URLs of contact pages >)
|
|
40
40
|
WikipediaRestClient.setUserAgent("someone@gmail.com")
|
41
41
|
```
|
42
42
|
|
43
|
+
### Set Language
|
44
|
+
By using this method, We can set the language in the REST API (Default lanuage is English).
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
WikipediaRestClient.set_language(<LANGUAGE_CODE>)
|
48
|
+
```
|
49
|
+
**Example**
|
50
|
+
```ruby
|
51
|
+
WikipediaRestClient.set_language("de") # To set the language as German.
|
52
|
+
WikipediaRestClient.set_language("fr") # To set the language as French.
|
53
|
+
```
|
43
54
|
### Page Summary
|
44
55
|
It will return details of the Wikipedia page for the query string.
|
45
56
|
|
@@ -261,6 +272,9 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
261
272
|
|
262
273
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
263
274
|
|
275
|
+
## Author
|
276
|
+
#### Balaji Ramasubramanian
|
277
|
+
|
264
278
|
## Contributing
|
265
279
|
|
266
280
|
Bug reports and pull requests are welcome on GitHub at https://github.com/Balaji-Ramasubramanian/wikipedia_rest_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module WikipediaRestClient
|
2
2
|
|
3
|
+
# Protocol of the URL
|
4
|
+
PROTOCOL = "https://"
|
3
5
|
# Base URL of the Wikipedia REST API.
|
4
|
-
BASE_URL = "
|
6
|
+
BASE_URL = ".wikipedia.org/api/rest_v1"
|
5
7
|
# URL parameters that are used to fetch the page content.
|
6
8
|
PAGE_URL = "/page/summary/"
|
7
9
|
# URL parameters that are used to fetch random page from Wikipedia.
|
@@ -14,6 +14,8 @@ require 'nokogiri'
|
|
14
14
|
module WikipediaRestClient
|
15
15
|
# header options to be passed through HTTP requests.
|
16
16
|
@@options = {}
|
17
|
+
# language code
|
18
|
+
@@language_code = "en"
|
17
19
|
# @param username [String] Email address or URLs of contact pages
|
18
20
|
# @return [nil]
|
19
21
|
# This method will set up the User-Agent header to the HTTP request.
|
@@ -28,6 +30,21 @@ module WikipediaRestClient
|
|
28
30
|
}
|
29
31
|
end
|
30
32
|
|
33
|
+
# @param language_code [String] The Language code
|
34
|
+
# @return [nil]
|
35
|
+
# By using this method you can set the language in the REST API (Default lanuage is English).
|
36
|
+
#
|
37
|
+
# Example:
|
38
|
+
#
|
39
|
+
# WikipediaRestClient.set_language("de")
|
40
|
+
# => Sets the language as German
|
41
|
+
# WikipediaRestClient.set_language("fr")
|
42
|
+
# => Sets the language as French
|
43
|
+
#
|
44
|
+
def self.set_language(language_code)
|
45
|
+
@@language_code = language_code
|
46
|
+
end
|
47
|
+
|
31
48
|
# @param title [String] A Wikipedia page title that has to be fetched.
|
32
49
|
# @return [WikipediaRestClient::Page] WikipediaRestClient::Page object which contains the data about the specified title.
|
33
50
|
# This method gets search query as a parameter and returns an object that contains the data about the specified Wikipedia page.
|
@@ -94,11 +111,12 @@ module WikipediaRestClient
|
|
94
111
|
#
|
95
112
|
def self.get_page(title)
|
96
113
|
title = URI::encode(title)
|
97
|
-
page_url = BASE_URL + PAGE_URL + title
|
114
|
+
page_url = PROTOCOL + @@language_code + BASE_URL + PAGE_URL + title
|
98
115
|
page_response = HTTParty.get(page_url, @@options)
|
99
116
|
page = Page.new(page_response)
|
100
117
|
page
|
101
118
|
end
|
119
|
+
|
102
120
|
# @param null
|
103
121
|
# @return [WikipediaRestClient::Page] WikipediaRestClient::Page object which returns a random page from Wikipedia.
|
104
122
|
# This method will return a random page from Wikipedia.
|
@@ -119,7 +137,7 @@ module WikipediaRestClient
|
|
119
137
|
# => "<Returns the URL of the image>"
|
120
138
|
#
|
121
139
|
def self.get_random
|
122
|
-
random_url = BASE_URL + RANDOM_PAGE_URL
|
140
|
+
random_url = PROTOCOL + @@language_code + BASE_URL + RANDOM_PAGE_URL
|
123
141
|
random_page_response = JSON.parse(HTTParty.get(random_url, @@options))
|
124
142
|
random_title = random_page_response["uri"].gsub("/en.wikipedia.org/v1/page/random/../summary/","")
|
125
143
|
random_page = get_page(random_title)
|
@@ -151,7 +169,7 @@ module WikipediaRestClient
|
|
151
169
|
# => 138192
|
152
170
|
#
|
153
171
|
def self.get_featured_article( date = Time.now.strftime("%Y/%m/%d") )
|
154
|
-
url = BASE_URL + FEATURED_ARTICLE + date
|
172
|
+
url = PROTOCOL + @@language_code + BASE_URL + FEATURED_ARTICLE + date
|
155
173
|
response = HTTParty.get(url, @@options)
|
156
174
|
article = FeaturedArticle.new.featured_article(response)
|
157
175
|
page = Page.new(article)
|
@@ -194,7 +212,7 @@ module WikipediaRestClient
|
|
194
212
|
# - description_text
|
195
213
|
#
|
196
214
|
def self.get_image_of_the_day(date = Time.now.strftime("%Y/%m/%d") )
|
197
|
-
url = BASE_URL + FEATURED_ARTICLE + date
|
215
|
+
url = PROTOCOL + @@language_code + BASE_URL + FEATURED_ARTICLE + date
|
198
216
|
response = HTTParty.get(url, @@options)
|
199
217
|
image = ImageOfTheDay.new(response)
|
200
218
|
image
|
@@ -220,7 +238,7 @@ module WikipediaRestClient
|
|
220
238
|
# => "United States Army officer Robert Bales murdered sixteen civilians and wounded six others in the Panjwayi District of Kandahar Province, Afghanistan."
|
221
239
|
#
|
222
240
|
def self.get_on_this_day(date = Time.now.strftime("%Y/%m/%d"))
|
223
|
-
url = BASE_URL + FEATURED_ARTICLE + date
|
241
|
+
url = PROTOCOL + @@language_code + BASE_URL + FEATURED_ARTICLE + date
|
224
242
|
response = HTTParty.get(url, @@options)
|
225
243
|
response["onthisday"]
|
226
244
|
end
|
@@ -239,7 +257,7 @@ module WikipediaRestClient
|
|
239
257
|
# => Returns Array of link pages related to that news
|
240
258
|
#
|
241
259
|
def self.get_news(date = Time.now.strftime("%Y/%m/%d"))
|
242
|
-
url = BASE_URL + FEATURED_ARTICLE + date
|
260
|
+
url = PROTOCOL + @@language_code + BASE_URL + FEATURED_ARTICLE + date
|
243
261
|
response = HTTParty.get(url, @@options)
|
244
262
|
news = WikipediaRestClient.parsed_news(response["news"])
|
245
263
|
news
|
@@ -263,7 +281,7 @@ module WikipediaRestClient
|
|
263
281
|
# => "https://en.wikipedia.org/wiki/Elizabeth_II"
|
264
282
|
#
|
265
283
|
def self.get_most_read(date = Time.now.strftime("%Y/%m/%d"))
|
266
|
-
url = BASE_URL + FEATURED_ARTICLE + date
|
284
|
+
url = PROTOCOL + @@language_code + BASE_URL + FEATURED_ARTICLE + date
|
267
285
|
response = HTTParty.get(url, @@options)
|
268
286
|
response["mostread"]
|
269
287
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikipedia_rest_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Balaji
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,7 +102,6 @@ executables: []
|
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
-
- ".DS_Store"
|
106
105
|
- ".gitignore"
|
107
106
|
- ".rspec"
|
108
107
|
- ".travis.yml"
|
data/.DS_Store
DELETED
Binary file
|