wikipedia_rest_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +274 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/wikipedia_rest_client.rb +283 -0
- data/lib/wikipedia_rest_client/featured_article.rb +25 -0
- data/lib/wikipedia_rest_client/image_of_the_day.rb +56 -0
- data/lib/wikipedia_rest_client/page.rb +208 -0
- data/lib/wikipedia_rest_client/utils.rb +12 -0
- data/lib/wikipedia_rest_client/version.rb +4 -0
- data/wikipedia_rest_client.gemspec +45 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c452900722d27ada17549e2b5c55ee1b1c7ebda6325c801f645d072ac02db6f
|
4
|
+
data.tar.gz: d6a092296053ccba45997df0b7d018235bcf439ea4c9ee980eb980f1dde99a1c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c215658d8f812a68d7f6ebe302e5936caf08445e0983e2fab32fc1e1079bdb3cb3fdf5c1e7561e061c00783c98f7ffbc7921945e8ebc2c0b78a24bb9d59354d
|
7
|
+
data.tar.gz: 4b38f3542b2c1eac428b3b62cc80985384bbdeb6e5ad8d1597aa94f084e5fe8f33d28aaca245d0e91ed91910ebb96740f887f6110b4d9c4d9eee409bb3ddd4d1
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at balaji030698@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wikipedia_rest_client (0.0.1)
|
5
|
+
httparty (~> 0.15.6)
|
6
|
+
json (~> 2.0.2)
|
7
|
+
nokogiri (>= 1.6.8)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
diff-lcs (1.3)
|
13
|
+
httparty (0.15.7)
|
14
|
+
multi_xml (>= 0.5.2)
|
15
|
+
json (2.0.4)
|
16
|
+
mini_portile2 (2.3.0)
|
17
|
+
multi_xml (0.6.0)
|
18
|
+
nokogiri (1.8.2)
|
19
|
+
mini_portile2 (~> 2.3.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.7.0)
|
22
|
+
rspec-core (~> 3.7.0)
|
23
|
+
rspec-expectations (~> 3.7.0)
|
24
|
+
rspec-mocks (~> 3.7.0)
|
25
|
+
rspec-core (3.7.0)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-expectations (3.7.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-mocks (3.7.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-support (3.7.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 1.16)
|
40
|
+
rake (~> 10.0)
|
41
|
+
rspec (~> 3.0)
|
42
|
+
wikipedia_rest_client!
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Balaji
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,274 @@
|
|
1
|
+
# WikipediaRestClient
|
2
|
+
|
3
|
+
wikipedia_rest_client is a ruby gem to ease your usage of the Wikipedia REST API. You can find the Wikipedia REST API [here](https://en.wikipedia.org/api/rest_v1/#/).
|
4
|
+
By using this gem we can get the following,
|
5
|
+
- Wikipedia page details for a given topic.
|
6
|
+
- Featured article.
|
7
|
+
- Picture of the day.
|
8
|
+
- News.
|
9
|
+
- Most-read articles of the day.
|
10
|
+
- On This Day.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'wikipedia_rest_client'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install wikipedia_rest_client
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Set User Agent
|
31
|
+
Set a unique User-Agent or Api-User-Agent header that allows us to contact you quickly.
|
32
|
+
|
33
|
+
Note: Setting User-Agent is optional but it is a good practice to handle more HTTPS requests for the API.
|
34
|
+
```ruby
|
35
|
+
WikipediaRestClient.setUserAgent(< Email addresses or URLs of contact pages >)
|
36
|
+
```
|
37
|
+
|
38
|
+
**Example**
|
39
|
+
```ruby
|
40
|
+
WikipediaRestClient.setUserAgent("someone@gmail.com")
|
41
|
+
```
|
42
|
+
|
43
|
+
### Page Summary
|
44
|
+
It will return details of the Wikipedia page for the query string.
|
45
|
+
|
46
|
+
**Example**
|
47
|
+
```ruby
|
48
|
+
page = WikipediaRestClient.get_page("Indian President")
|
49
|
+
#Returns an object that contains contents of the required page
|
50
|
+
page.title
|
51
|
+
#=> "President of India"
|
52
|
+
page.text
|
53
|
+
#=> "The President of the Republic of India is the head of state of India and the commander-in-chief of the Indian Armed Forces."
|
54
|
+
page.image_url
|
55
|
+
#=> "https://upload.wikimedia.org/wikipedia/commons/8/80/Ram_Nath_Kovind_2017.jpg"
|
56
|
+
page.url
|
57
|
+
#=> "https://en.wikipedia.org/wiki/President_of_India"
|
58
|
+
page.pageid
|
59
|
+
#=> 141896
|
60
|
+
page.description
|
61
|
+
#=> "executive head of state of the Republic of India"
|
62
|
+
```
|
63
|
+
The Page class contains the following information,
|
64
|
+
- type
|
65
|
+
- title
|
66
|
+
- display_title
|
67
|
+
- namespace_id
|
68
|
+
- namespace_text
|
69
|
+
- titles_canonical
|
70
|
+
- titles_normalized
|
71
|
+
- titles_display
|
72
|
+
- pageid
|
73
|
+
- thumbnail_source
|
74
|
+
- thumbnail_width
|
75
|
+
- thumbnail_height
|
76
|
+
- lang
|
77
|
+
- dir
|
78
|
+
- revision
|
79
|
+
- tid
|
80
|
+
- timestamp
|
81
|
+
- description
|
82
|
+
- image_url
|
83
|
+
- image_width
|
84
|
+
- image_height
|
85
|
+
- url_desktop_page
|
86
|
+
- url_desktop_revisions
|
87
|
+
- url_desktop_edit
|
88
|
+
- url_desktop_talk
|
89
|
+
- url_mobile_page
|
90
|
+
- url_mobile_revisions
|
91
|
+
- url_mobile_edit
|
92
|
+
- url_mobile_talk
|
93
|
+
- api_urls_summary
|
94
|
+
- api_urls_metadata
|
95
|
+
- api_urls_references
|
96
|
+
- api_urls_media
|
97
|
+
- api_urls_edit_html
|
98
|
+
- api_urls_talk_page_html
|
99
|
+
- text
|
100
|
+
- text_html
|
101
|
+
- normalized_title
|
102
|
+
- url
|
103
|
+
|
104
|
+
### Random Article
|
105
|
+
|
106
|
+
**Example**
|
107
|
+
```ruby
|
108
|
+
page = WikipediaRestClient.get_random
|
109
|
+
#=> Return a random page from wikipedia
|
110
|
+
page.title
|
111
|
+
#=> "Adams Glacier (Victoria Land)"
|
112
|
+
page.text
|
113
|
+
#=> "Adams Glacier is a small glacier immediately south of Miers Glacier in Victoria Land. The heads of Adams and Miers glaciers, both located in the Miers Valley, are separated by a low ridge, and the east end of this ridge is almost completely surrounded by the snouts of the two glaciers, which nearly meet in the bottom of the valley, about 1 mile (1.6 km) above Lake Miers, into which they drain. It was named by the New Zealand Northern Survey Party of the Commonwealth Trans-Antarctic Expedition (1956–58) after Lieutenant Jameson Adams, second in command of the shore party of the British Antarctic Expedition (1907–09), who was one of the men to accompany Ernest Shackleton to within 97 miles (156 km) of the South Pole."
|
114
|
+
page.url
|
115
|
+
#=> "https://en.wikipedia.org/wiki/Adams_Glacier_(Victoria_Land)"
|
116
|
+
page.pageid
|
117
|
+
#=> 16524953
|
118
|
+
page.image_url
|
119
|
+
#=> "https://upload.wikimedia.org/wikipedia/commons/2/24/Antarctica_relief_location_map.jpg"
|
120
|
+
|
121
|
+
```
|
122
|
+
|
123
|
+
### Featured Article
|
124
|
+
|
125
|
+
Returns the Page object of the featured article
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
article_of_the_day = WikipediaRestClient.get_featured_article
|
129
|
+
#=> Returns today's featured article
|
130
|
+
|
131
|
+
article = WikipediaRestClient.get_featured_article(<DATE>) #Date Should be in YYYY/MM/DD Format
|
132
|
+
#=> Returns featured article for the specified date
|
133
|
+
```
|
134
|
+
|
135
|
+
|
136
|
+
**Example**
|
137
|
+
```ruby
|
138
|
+
old_article = WikipediaRestClient.get_featured_article("2018/05/10")
|
139
|
+
#=> Returns featured article dated (2018/05/10)
|
140
|
+
article.title
|
141
|
+
#=> "Russian_battleship_Pobeda"
|
142
|
+
article.image_url
|
143
|
+
#=> "https://upload.wikimedia.org/wikipedia/commons/0/01/Pobeda1904Port-Artur.jpg"
|
144
|
+
article.text
|
145
|
+
#=> "Pobeda was the last of the three Peresvet-class pre-dreadnought battleships built for the Imperial Russian Navy at the end of the nineteenth century. The ship was assigned to the Pacific Squadron upon completion and based at Port Arthur from 1903. During the Russo-Japanese War of 1904–1905, she participated in the battles of Port Arthur and the Yellow Sea. Having escaped serious damage in these engagements, Pobeda was sunk by gunfire during the Siege of Port Arthur, and then salvaged by the Japanese and placed into service under the name Suwo (周防)."
|
146
|
+
|
147
|
+
today_article = WikipediaRestClient.get_featured_article
|
148
|
+
#=> Returns featured article of the current day
|
149
|
+
today_article.title
|
150
|
+
#=> "Arlington,_Washington"
|
151
|
+
today_article.url
|
152
|
+
#=> "https://en.wikipedia.org/wiki/Arlington,_Washington"
|
153
|
+
today_article.pageid
|
154
|
+
#=> 138192
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
### Picture of the day
|
159
|
+
|
160
|
+
**Example**
|
161
|
+
```ruby
|
162
|
+
picture_of_the_day = WikipediaRestClient.get_image_of_the_day
|
163
|
+
#=> Returns image of the day from Wikipedia.
|
164
|
+
picture_of_the_day.title
|
165
|
+
#=> "File:Haus der Kulturen der Welt, Blaue Stunde, Berlin, 160521, ako.jpg"
|
166
|
+
picture_of_the_day.image_url
|
167
|
+
#=> "https://upload.wikimedia.org/wikipedia/commons/2/25/Haus_der_Kulturen_der_Welt%2C_Blaue_Stunde%2C_Berlin%2C_160521%2C_ako.jpg"
|
168
|
+
picture_of_the_day.image_height
|
169
|
+
#=> 3648
|
170
|
+
picture_of_the_day.thumbnail
|
171
|
+
#=> "https://upload.wikimedia.org/wikipedia/commons/thumb/2/25/Haus_der_Kulturen_der_Welt%2C_Blaue_Stunde%2C_Berlin%2C_160521%2C_ako.jpg/640px-Haus_der_Kulturen_der_Welt%2C_Blaue_Stunde%2C_Berlin%2C_160521%2C_ako.jpg"
|
172
|
+
picture_of_the_day_for_a_date = WikipediaRestClient.get_image_of_the_day("2017/03/12")
|
173
|
+
#=> Returns pictured of the day for the specified date ("YYYY/MM/DD")
|
174
|
+
picture_of_the_day_for_a_date.image_url
|
175
|
+
#=> "https://upload.wikimedia.org/wikipedia/commons/4/4b/Cyclosia_papilionaris-Kadavoor-2016-06-17-001.jpg"
|
176
|
+
picture_of_the_day_for_a_date.description_text
|
177
|
+
#=> "<i><a rel=\"mw:WikiLink/Interwiki\" href=\"https://en.wikipedia.org/wiki/Cyclosia%20papilionaris\" title=\"en:Cyclosia papilionaris\">Cyclosia papilionaris</a></i>, Drury's Jewel, is a moth in the <a rel=\"mw:WikiLink/Interwiki\" href=\"https://en.wikipedia.org/wiki/Zygaenidae\" title=\"en:Zygaenidae\">Zygaenidae</a> family. There are many subspecies and this is <i>Cyclosia papilionaris australinda</i> found in <a rel=\"mw:WikiLink/Interwiki\" href=\"https://en.wikipedia.org/wiki/South%20India\" title=\"en:South India\">South India</a>."
|
178
|
+
```
|
179
|
+
|
180
|
+
It will have the following information,
|
181
|
+
- title
|
182
|
+
- image_url
|
183
|
+
- image_width
|
184
|
+
- image_height
|
185
|
+
- thumbnail
|
186
|
+
- thumbnail_width
|
187
|
+
- thumbnail_height
|
188
|
+
- description_text
|
189
|
+
|
190
|
+
|
191
|
+
### On This Day
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
on_this_day_content = WikipediaRestClient.get_on_this_day
|
195
|
+
#=> Returns 'on this day' contents of the current date
|
196
|
+
on_that_day = WikipediaRestClient.get_on_this_day(<DATE>) #Date Should be in YYYY/MM/DD Format
|
197
|
+
#=> Returns 'on this day' contents of the specified date
|
198
|
+
```
|
199
|
+
|
200
|
+
**Example**
|
201
|
+
```ruby
|
202
|
+
on_this_day_content = WikipediaRestClient.get_on_this_day
|
203
|
+
#=> Returns Array of Hash values which contains 'on this day' contents
|
204
|
+
on_this_day_content[0]["text"]
|
205
|
+
#=> "A corroded oil pipeline in Santa Barbara County, California, burst, spilling 142,800 U.S. gallons (3,400 barrels) of crude oil onto one of the most biologically diverse coastlines of the U.S. West Coast."
|
206
|
+
on_this_day_content[0]["year"]
|
207
|
+
#=> 2013
|
208
|
+
on_this_day_content[0]["pages"]
|
209
|
+
#=> Returns Array of Wikipedia pages related to that topic
|
210
|
+
|
211
|
+
on_that_day = WikipediaRestClient.get_on_this_day("2018/03/11")
|
212
|
+
#=> Returns 'on this day' contents for the specified date
|
213
|
+
on_that_day[0]["text"]
|
214
|
+
#=> "United States Army officer Robert Bales murdered sixteen civilians and wounded six others in the Panjwayi District of Kandahar Province, Afghanistan."
|
215
|
+
```
|
216
|
+
|
217
|
+
### Get News
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
on_this_day_content = WikipediaRestClient.get_news
|
221
|
+
#=> Returns 'news' contents of the current date
|
222
|
+
on_that_day = WikipediaRestClient.get_news(<DATE>) #Date Should be in YYYY/MM/DD Format
|
223
|
+
#=> Returns 'news' contents of the specified date
|
224
|
+
```
|
225
|
+
|
226
|
+
**Example**
|
227
|
+
```ruby
|
228
|
+
news = WikipediaRestClient.get_news
|
229
|
+
#=> Returns Array of Hash values which contains news contents
|
230
|
+
news[0]["story"]
|
231
|
+
#=> "Incumbent Nicolás Maduro is re-elected President of Venezuela."
|
232
|
+
news[0]["links"]
|
233
|
+
#=> Returns Array of link pages related to that news
|
234
|
+
```
|
235
|
+
|
236
|
+
### Most-Read articles of the day
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
on_this_day_content = WikipediaRestClient.get_most_read
|
240
|
+
#=> Returns 'most read' contents of the current date
|
241
|
+
on_that_day = WikipediaRestClient.get_most_read(<DATE>) #Date Should be in YYYY/MM/DD Format
|
242
|
+
#=> Returns 'most read' contents of the specified date
|
243
|
+
```
|
244
|
+
|
245
|
+
***Example***
|
246
|
+
```ruby
|
247
|
+
most_read = WikipediaRestClient.get_most_read
|
248
|
+
#=> Returns Hash value
|
249
|
+
most_read["articles"][0]["views"]
|
250
|
+
#=> 709029
|
251
|
+
most_read["articles"][0]["title"]
|
252
|
+
#=> "Elizabeth_II"
|
253
|
+
most_read["articles"][0]["extract"]
|
254
|
+
#=> "Elizabeth II is Queen of the United Kingdom and fifteen other Commonwealth realms."
|
255
|
+
most_read["articles"][0]["content_urls"]["desktop"]["page"]
|
256
|
+
#=> "https://en.wikipedia.org/wiki/Elizabeth_II"
|
257
|
+
```
|
258
|
+
## Development
|
259
|
+
|
260
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
261
|
+
|
262
|
+
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
|
+
|
264
|
+
## Contributing
|
265
|
+
|
266
|
+
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.
|
267
|
+
|
268
|
+
## License
|
269
|
+
|
270
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
271
|
+
|
272
|
+
## Code of Conduct
|
273
|
+
|
274
|
+
Everyone interacting in the WikipediaRestClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Balaji-Ramasubramanian/wikipedia_rest_client/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wikipedia_rest_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,283 @@
|
|
1
|
+
require "wikipedia_rest_client/version"
|
2
|
+
require "wikipedia_rest_client/utils"
|
3
|
+
require "wikipedia_rest_client/page"
|
4
|
+
require "wikipedia_rest_client/featured_article"
|
5
|
+
require "wikipedia_rest_client/image_of_the_day"
|
6
|
+
|
7
|
+
require 'httparty'
|
8
|
+
require 'json'
|
9
|
+
require 'date'
|
10
|
+
require 'uri'
|
11
|
+
require 'nokogiri'
|
12
|
+
|
13
|
+
# @author Balaji
|
14
|
+
module WikipediaRestClient
|
15
|
+
# header options to be passed through HTTP requests.
|
16
|
+
@@options = {}
|
17
|
+
# @param username [String] Email address or URLs of contact pages
|
18
|
+
# @return [nil]
|
19
|
+
# This method will set up the User-Agent header to the HTTP request.
|
20
|
+
#
|
21
|
+
# Example:
|
22
|
+
#
|
23
|
+
# WikipediaRestClient.setUserAgent("someone@gmail.com")
|
24
|
+
#
|
25
|
+
def self.setUserAgent(username)
|
26
|
+
@@options = {
|
27
|
+
headers: {"User-Agent" => username}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param title [String] A Wikipedia page title that has to be fetched.
|
32
|
+
# @return [WikipediaRestClient::Page] WikipediaRestClient::Page object which contains the data about the specified title.
|
33
|
+
# This method gets search query as a parameter and returns an object that contains the data about the specified Wikipedia page.
|
34
|
+
#
|
35
|
+
# Example:
|
36
|
+
#
|
37
|
+
# page = WikipediaRestClient.get_page("Indian President")
|
38
|
+
# => "<Returns an object that contains contents of the required page>"
|
39
|
+
# page.title
|
40
|
+
# => "President of India"
|
41
|
+
# page.text
|
42
|
+
# => "The President of the Republic of India is the head of state of India and the commander-in-chief of the Indian Armed Forces."
|
43
|
+
# page.image_url
|
44
|
+
# => "<Returns the image url of the page>"
|
45
|
+
# The Page class contains the following information,
|
46
|
+
# page.url
|
47
|
+
# => "https://en.wikipedia.org/wiki/President_of_India"
|
48
|
+
# page.pageid
|
49
|
+
# => 141896
|
50
|
+
# page.description
|
51
|
+
# => "executive head of state of the Republic of India"
|
52
|
+
#
|
53
|
+
# Page class contains the following methods,
|
54
|
+
#
|
55
|
+
# - type
|
56
|
+
# - title
|
57
|
+
# - display_title
|
58
|
+
# - namespace_id
|
59
|
+
# - namespace_text
|
60
|
+
# - titles_canonical
|
61
|
+
# - titles_normalized
|
62
|
+
# - titles_display
|
63
|
+
# - pageid
|
64
|
+
# - thumbnail_source
|
65
|
+
# - thumbnail_width
|
66
|
+
# - thumbnail_height
|
67
|
+
# - lang
|
68
|
+
# - dir
|
69
|
+
# - revision
|
70
|
+
# - tid
|
71
|
+
# - timestamp
|
72
|
+
# - description
|
73
|
+
# - image_url
|
74
|
+
# - image_width
|
75
|
+
# - image_height
|
76
|
+
# - url_desktop_page
|
77
|
+
# - url_desktop_revisions
|
78
|
+
# - url_desktop_edit
|
79
|
+
# - url_desktop_talk
|
80
|
+
# - url_mobile_page
|
81
|
+
# - url_mobile_revisions
|
82
|
+
# - url_mobile_edit
|
83
|
+
# - url_mobile_talk
|
84
|
+
# - api_urls_summary
|
85
|
+
# - api_urls_metadata
|
86
|
+
# - api_urls_references
|
87
|
+
# - api_urls_media
|
88
|
+
# - api_urls_edit_html
|
89
|
+
# - api_urls_talk_page_html
|
90
|
+
# - text
|
91
|
+
# - text_html
|
92
|
+
# - normalized_title
|
93
|
+
# - url
|
94
|
+
#
|
95
|
+
def self.get_page(title)
|
96
|
+
title = URI::encode(title)
|
97
|
+
page_url = BASE_URL + PAGE_URL + title
|
98
|
+
page_response = HTTParty.get(page_url, @@options)
|
99
|
+
page = Page.new(page_response)
|
100
|
+
page
|
101
|
+
end
|
102
|
+
# @param null
|
103
|
+
# @return [WikipediaRestClient::Page] WikipediaRestClient::Page object which returns a random page from Wikipedia.
|
104
|
+
# This method will return a random page from Wikipedia.
|
105
|
+
#
|
106
|
+
# Example:
|
107
|
+
#
|
108
|
+
# page = WikipediaRestClient.get_random
|
109
|
+
# => Return a random page from wikipedia
|
110
|
+
# page.title
|
111
|
+
# => "Adams Glacier (Victoria Land)"
|
112
|
+
# page.text
|
113
|
+
# => "Adams Glacier is a small glacier immediately south of Miers Glacier in Victoria Land. The heads of Adams and Miers glaciers, both located in the Miers Valley, are separated by a low ridge, and the east end of this ridge is almost completely surrounded by the snouts of the two glaciers, which nearly meet in the bottom of the valley, about 1 mile (1.6 km) above Lake Miers, into which they drain. It was named by the New Zealand Northern Survey Party of the Commonwealth Trans-Antarctic Expedition (1956–58) after Lieutenant Jameson Adams, second in command of the shore party of the British Antarctic Expedition (1907–09), who was one of the men to accompany Ernest Shackleton to within 97 miles (156 km) of the South Pole."
|
114
|
+
# page.url
|
115
|
+
# => "https://en.wikipedia.org/wiki/Adams_Glacier_(Victoria_Land)"
|
116
|
+
# page.pageid
|
117
|
+
# => 16524953
|
118
|
+
# page.image_url
|
119
|
+
# => "<Returns the URL of the image>"
|
120
|
+
#
|
121
|
+
def self.get_random
|
122
|
+
random_url = BASE_URL + RANDOM_PAGE_URL
|
123
|
+
random_page_response = JSON.parse(HTTParty.get(random_url, @@options))
|
124
|
+
random_title = random_page_response["uri"].gsub("/en.wikipedia.org/v1/page/random/../summary/","")
|
125
|
+
random_page = get_page(random_title)
|
126
|
+
random_page
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
# @param date [String] The string must be a date in YYYY/MM/DD format. The default parameter is the current date.
|
131
|
+
# @return [WikipediaRestClient::Page] An object of WikipediaRestClient::Page.
|
132
|
+
# This method will return the featured article of the specified date from Wikipedia(Default parameter is current date).
|
133
|
+
#
|
134
|
+
# Example:
|
135
|
+
#
|
136
|
+
# old_article = WikipediaRestClient.get_featured_article("2018/05/10")
|
137
|
+
# => Returns featured article dated (2018/05/10)
|
138
|
+
# article.title
|
139
|
+
# => "Russian_battleship_Pobeda"
|
140
|
+
# article.image_url
|
141
|
+
# => "<Returns the URL of the image>"
|
142
|
+
# article.text
|
143
|
+
# => "Pobeda was the last of the three Peresvet-class pre-dreadnought battleships built for the Imperial Russian Navy at the end of the nineteenth century. The ship was assigned to the Pacific Squadron upon completion and based at Port Arthur from 1903. During the Russo-Japanese War of 1904–1905, she participated in the battles of Port Arthur and the Yellow Sea. Having escaped serious damage in these engagements, Pobeda was sunk by gunfire during the Siege of Port Arthur, and then salvaged by the Japanese and placed into service under the name Suwo (周防)."
|
144
|
+
# today_article = WikipediaRestClient.get_featured_article
|
145
|
+
# => Returns featured article of the current day
|
146
|
+
# today_article.title
|
147
|
+
# => "Arlington,_Washington"
|
148
|
+
# today_article.url
|
149
|
+
# => "https://en.wikipedia.org/wiki/Arlington,_Washington"
|
150
|
+
# today_article.pageid
|
151
|
+
# => 138192
|
152
|
+
#
|
153
|
+
def self.get_featured_article( date = Time.now.strftime("%Y/%m/%d") )
|
154
|
+
url = BASE_URL + FEATURED_ARTICLE + date
|
155
|
+
response = HTTParty.get(url, @@options)
|
156
|
+
article = FeaturedArticle.new.featured_article(response)
|
157
|
+
page = Page.new(article)
|
158
|
+
page
|
159
|
+
end
|
160
|
+
|
161
|
+
# @param date [String] The string must be a date in YYYY/MM/DD format. default parameter is current date.
|
162
|
+
# @return [WikipediaRestClient::IageOfTheDay] An object of WikipediaRestClient::ImageOfTheDay.
|
163
|
+
# This method will return 'Image of the day' content of the specified date from Wikipedia(Default parameter is current date).
|
164
|
+
#
|
165
|
+
# Example:
|
166
|
+
#
|
167
|
+
# picture_of_the_day = WikipediaRestClient.get_image_of_the_day
|
168
|
+
# => Returns picture of the day from Wikipedia.
|
169
|
+
# picture_of_the_day.title
|
170
|
+
# => "File:Haus der Kulturen der Welt, Blaue Stunde, Berlin, 160521, ako.jpg"
|
171
|
+
# picture_of_the_day.image_url
|
172
|
+
# => "<Returns the URL of the image>"
|
173
|
+
# picture_of_the_day.image_height
|
174
|
+
# => 3648
|
175
|
+
# picture_of_the_day.thumbnail
|
176
|
+
# => "<Returns the thumbnail URL of the image>"
|
177
|
+
# picture_of_the_day_for_a_date = WikipediaRestClient.get_image_of_the_day("2017/03/12")
|
178
|
+
# => Returns pictured of the day for the specified date ("YYYY/MM/DD")
|
179
|
+
# picture_of_the_day_for_a_date.image_url
|
180
|
+
# => "<Returns the URL of the image>"
|
181
|
+
# picture_of_the_day_for_a_date.description_text
|
182
|
+
# => "<i><a rel=\"mw:WikiLink/Interwiki\" href=\"https://en.wikipedia.org/wiki/Cyclosia%20papilionaris\" title=\"en:Cyclosia papilionaris\">Cyclosia papilionaris</a></i>, Drury's Jewel, is a moth in the <a rel=\"mw:WikiLink/Interwiki\" href=\"https://en.wikipedia.org/wiki/Zygaenidae\" title=\"en:Zygaenidae\">Zygaenidae</a> family. There are many subspecies and this is <i>Cyclosia papilionaris australinda</i> found in <a rel=\"mw:WikiLink/Interwiki\" href=\"https://en.wikipedia.org/wiki/South%20India\" title=\"en:South India\">South India</a>."
|
183
|
+
#
|
184
|
+
#
|
185
|
+
# It will have the following information,
|
186
|
+
#
|
187
|
+
# - title
|
188
|
+
# - image_url
|
189
|
+
# - image_width
|
190
|
+
# - image_height
|
191
|
+
# - thumbnail
|
192
|
+
# - thumbnail_width
|
193
|
+
# - thumbnail_height
|
194
|
+
# - description_text
|
195
|
+
#
|
196
|
+
def self.get_image_of_the_day(date = Time.now.strftime("%Y/%m/%d") )
|
197
|
+
url = BASE_URL + FEATURED_ARTICLE + date
|
198
|
+
response = HTTParty.get(url, @@options)
|
199
|
+
image = ImageOfTheDay.new(response)
|
200
|
+
image
|
201
|
+
end
|
202
|
+
|
203
|
+
# @param date [String] The string must be a date in YYYY/MM/DD format.The default parameter is the current date.
|
204
|
+
# @return [JSON] "on this day" content from Wikipedia.
|
205
|
+
# This method will be used to get the 'On this day' content from Wikipedia. The default parameter is the current date. If you need you can pass a date in YYYY/MM/DD format and get the "on this day " content for that specified date.
|
206
|
+
#
|
207
|
+
# Example:
|
208
|
+
#
|
209
|
+
# on_this_day_content = WikipediaRestClient.get_on_this_day
|
210
|
+
# => Returns Array of Hash values which contains 'on this day' contents
|
211
|
+
# on_this_day_content[0]["text"]
|
212
|
+
# => "A corroded oil pipeline in Santa Barbara County, California, burst, spilling 142,800 U.S. gallons (3,400 barrels) of crude oil onto one of the most biologically diverse coastlines of the U.S. West Coast."
|
213
|
+
# on_this_day_content[0]["year"]
|
214
|
+
# => 2013
|
215
|
+
# on_this_day_content[0]["pages"]
|
216
|
+
# => Returns Array of Wikipedia pages related to that topic
|
217
|
+
# on_that_day = WikipediaRestClient.get_on_this_day("2018/03/11")
|
218
|
+
# => Returns 'on this day' contents for the specified date
|
219
|
+
# on_that_day[0]["text"]
|
220
|
+
# => "United States Army officer Robert Bales murdered sixteen civilians and wounded six others in the Panjwayi District of Kandahar Province, Afghanistan."
|
221
|
+
#
|
222
|
+
def self.get_on_this_day(date = Time.now.strftime("%Y/%m/%d"))
|
223
|
+
url = BASE_URL + FEATURED_ARTICLE + date
|
224
|
+
response = HTTParty.get(url, @@options)
|
225
|
+
response["onthisday"]
|
226
|
+
end
|
227
|
+
|
228
|
+
# @param date [String] The string must be a date in YYYY/MM/DD format. The default parameter is the current date.
|
229
|
+
# @return [JSON] JSON object that contains news contents from Wikipedia page.
|
230
|
+
# This method will return the list of news that is in the form of JSON object. Each news content will contain news and their related links.
|
231
|
+
#
|
232
|
+
# Example:
|
233
|
+
#
|
234
|
+
# news = WikipediaRestClient.get_news
|
235
|
+
# => Returns Array of Hash values which contains news contents
|
236
|
+
# news[0]["story"]
|
237
|
+
# => "Incumbent Nicolás Maduro is re-elected President of Venezuela."
|
238
|
+
# news[0]["links"]
|
239
|
+
# => Returns Array of link pages related to that news
|
240
|
+
#
|
241
|
+
def self.get_news(date = Time.now.strftime("%Y/%m/%d"))
|
242
|
+
url = BASE_URL + FEATURED_ARTICLE + date
|
243
|
+
response = HTTParty.get(url, @@options)
|
244
|
+
news = WikipediaRestClient.parsed_news(response["news"])
|
245
|
+
news
|
246
|
+
end
|
247
|
+
|
248
|
+
# @param date [String] The string must be a date in YYYY/MM/DD format. The default parameter is the current date.
|
249
|
+
# @return [JSON] an JSON object that contains the most-read contents of the specified date
|
250
|
+
# This method will return the contents of mostread pages of the specified date(Default is current date).
|
251
|
+
#
|
252
|
+
# Example:
|
253
|
+
#
|
254
|
+
# most_read = WikipediaRestClient.get_most_read
|
255
|
+
# => Returns Hash value
|
256
|
+
# most_read["articles"][0]["views"]
|
257
|
+
# => 709029
|
258
|
+
# most_read["articles"][0]["title"]
|
259
|
+
# => "Elizabeth_II"
|
260
|
+
# most_read["articles"][0]["extract"]
|
261
|
+
# => "Elizabeth II is Queen of the United Kingdom and fifteen other Commonwealth realms."
|
262
|
+
# most_read["articles"][0]["content_urls"]["desktop"]["page"]
|
263
|
+
# => "https://en.wikipedia.org/wiki/Elizabeth_II"
|
264
|
+
#
|
265
|
+
def self.get_most_read(date = Time.now.strftime("%Y/%m/%d"))
|
266
|
+
url = BASE_URL + FEATURED_ARTICLE + date
|
267
|
+
response = HTTParty.get(url, @@options)
|
268
|
+
response["mostread"]
|
269
|
+
end
|
270
|
+
|
271
|
+
# @param news [JSON] The JSON object from the get_news method will be used here.
|
272
|
+
# @return [JSON] Returns the parsed HTML contents inside the JSON object of get_news method.
|
273
|
+
def self.parsed_news(news)
|
274
|
+
news.each do |news|
|
275
|
+
data = news["story"]
|
276
|
+
parsed_data = Nokogiri::HTML(data)
|
277
|
+
news["story"] = parsed_data.text
|
278
|
+
end
|
279
|
+
news
|
280
|
+
end
|
281
|
+
|
282
|
+
|
283
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module WikipediaRestClient
|
2
|
+
|
3
|
+
# @author Balaji
|
4
|
+
class FeaturedArticle
|
5
|
+
|
6
|
+
# Today's Featured Article from Wikipedia page.
|
7
|
+
def featured_article(json)
|
8
|
+
@data = json
|
9
|
+
if @data["tfa"]
|
10
|
+
then
|
11
|
+
@data["tfa"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Image of the day content from Wikipedia page.
|
16
|
+
def image_of_the_day
|
17
|
+
@data["image"]["image"]["source"]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
module WikipediaRestClient
|
3
|
+
|
4
|
+
# @author Balaji
|
5
|
+
class ImageOfTheDay
|
6
|
+
|
7
|
+
# Returns
|
8
|
+
def initialize(json)
|
9
|
+
@data = json["image"]
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns the tile of ImageOfTheDay
|
13
|
+
def title
|
14
|
+
@data["title"]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the URL of the image
|
18
|
+
def image_url
|
19
|
+
@data["image"]["source"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns width of the image
|
23
|
+
def image_width
|
24
|
+
@data["image"]["width"]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns height of the image
|
28
|
+
def image_height
|
29
|
+
@data["image"]["height"]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns the source of the thumbnail image
|
33
|
+
def thumbnail
|
34
|
+
@data["thumbnail"]["source"]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns width of thumbnail
|
38
|
+
def thumbnail_width
|
39
|
+
@data["thumbnail"]["width"]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns height of thumbnail
|
43
|
+
def thumbnail_height
|
44
|
+
@data["thumbnail"]["height"]
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns description about the image
|
48
|
+
def description_text
|
49
|
+
html_data = @data["description"]["text"]
|
50
|
+
parsed_data = Nokogiri::HTML(html_data)
|
51
|
+
parsed_data.text
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
module WikipediaRestClient
|
2
|
+
# WikipediaRestClient::Page class
|
3
|
+
# @author Balaji
|
4
|
+
class Page
|
5
|
+
|
6
|
+
# initialize the data of the Page object
|
7
|
+
def initialize(json)
|
8
|
+
@data = json
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns the type of the Page
|
12
|
+
def type
|
13
|
+
@data["type"]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the title of the Page
|
17
|
+
def title
|
18
|
+
@data["title"]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the display title of the Page
|
22
|
+
def display_title
|
23
|
+
@data["displaytitle"]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the namepade id of the page
|
27
|
+
def namespace_id
|
28
|
+
@data["namespace"]["id"]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the namespace text
|
32
|
+
def namespace_text
|
33
|
+
@data["namespace"]["text"]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the tile (canonical)
|
37
|
+
def titles_canonical
|
38
|
+
@data["titles"]["canonical"]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the title (normalized)
|
42
|
+
def titles_normalized
|
43
|
+
@data["titles"]["normalized"]
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns the title (display)
|
47
|
+
def titles_display
|
48
|
+
@data["titles"]["display"]
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the pageid of that page
|
52
|
+
def pageid
|
53
|
+
@data["pageid"]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the source of the thumbnail image
|
57
|
+
def thumbnail_source
|
58
|
+
@data["thumbnail"]["source"]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns the width of the thumbnail image
|
62
|
+
def thumbnail_width
|
63
|
+
@data["thumbnail"]["width"]
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns the height of the thumbnail image
|
67
|
+
def thumbnail_height
|
68
|
+
@data["thumbnail"]["height"]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns the language of that page
|
72
|
+
def lang
|
73
|
+
@data["lang"]
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns dir
|
77
|
+
def dir
|
78
|
+
@data["dir"]
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns revision
|
82
|
+
def revision
|
83
|
+
@data["revision"]
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns tid
|
87
|
+
def tid
|
88
|
+
@data["tid"]
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns timestamp
|
92
|
+
def timestamp
|
93
|
+
@data["timestamp"]
|
94
|
+
end
|
95
|
+
|
96
|
+
# Returns description of that page content
|
97
|
+
def description
|
98
|
+
@data["description"]
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns the url of the main image in the page
|
102
|
+
def image_url
|
103
|
+
@data["originalimage"]["source"]
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns width of the main image it the page
|
107
|
+
def image_width
|
108
|
+
@data["originalimage"]["width"]
|
109
|
+
end
|
110
|
+
|
111
|
+
# Returns height of the main image it the page
|
112
|
+
def image_height
|
113
|
+
@data["originalimage"]["height"]
|
114
|
+
end
|
115
|
+
|
116
|
+
# Returns page url (desktop)
|
117
|
+
def url_desktop_page
|
118
|
+
@data["content_urls"]["desktop"]["page"]
|
119
|
+
end
|
120
|
+
|
121
|
+
# Returns revision url (desktop)
|
122
|
+
def url_desktop_revisions
|
123
|
+
@data["content_urls"]["desktop"]["revision"]
|
124
|
+
end
|
125
|
+
|
126
|
+
# Returns edit url (desktop)
|
127
|
+
def url_desktop_edit
|
128
|
+
@data["content_urls"]["desktop"]["edit"]
|
129
|
+
end
|
130
|
+
|
131
|
+
# Returns talk url (desktop)
|
132
|
+
def url_desktop_talk
|
133
|
+
@data["content_urls"]["desktop"]["talk"]
|
134
|
+
end
|
135
|
+
|
136
|
+
# Returns page url (mobile)
|
137
|
+
def url_mobile_page
|
138
|
+
@data["content_urls"]["mobile"]["page"]
|
139
|
+
end
|
140
|
+
|
141
|
+
# Returns revision url (mobile)
|
142
|
+
def url_mobile_revisions
|
143
|
+
@data["content_urls"]["mobile"]["revision"]
|
144
|
+
end
|
145
|
+
|
146
|
+
# Returns mobile_edit url (mobile)
|
147
|
+
def url_mobile_edit
|
148
|
+
@data["content_urls"]["mobile"]["edit"]
|
149
|
+
end
|
150
|
+
|
151
|
+
# Returns mobile_talk url (mobile)
|
152
|
+
def url_mobile_talk
|
153
|
+
@data["content_urls"]["mobile"]["talk"]
|
154
|
+
end
|
155
|
+
|
156
|
+
# Returns summary url
|
157
|
+
def api_urls_summary
|
158
|
+
@data["api_urls"]["summary"]
|
159
|
+
end
|
160
|
+
|
161
|
+
# Returns metadata url
|
162
|
+
def api_urls_metadata
|
163
|
+
@data["api_urls"]["metadata"]
|
164
|
+
end
|
165
|
+
|
166
|
+
# Returns references rul
|
167
|
+
def api_urls_references
|
168
|
+
@data["api_urls"]["references"]
|
169
|
+
end
|
170
|
+
|
171
|
+
# Returns media url
|
172
|
+
def api_urls_media
|
173
|
+
@data["api_urls"]["media"]
|
174
|
+
end
|
175
|
+
|
176
|
+
# Returns edit_html url
|
177
|
+
def api_urls_edit_html
|
178
|
+
@data["api_urls"]["edit_html"]
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns talk_page_html url
|
182
|
+
def api_urls_talk_page_html
|
183
|
+
@data["api_urls"]["talk_page_html"]
|
184
|
+
end
|
185
|
+
|
186
|
+
# Returns the text of the page
|
187
|
+
def text
|
188
|
+
@data["extract"]
|
189
|
+
end
|
190
|
+
|
191
|
+
# Returns extract_html
|
192
|
+
def text_html
|
193
|
+
@data["extract_html"]
|
194
|
+
end
|
195
|
+
|
196
|
+
# Returns normalized title
|
197
|
+
def normalized_title
|
198
|
+
@data["normalizedtitle"]
|
199
|
+
end
|
200
|
+
|
201
|
+
# Returns page url (desktop)
|
202
|
+
def url
|
203
|
+
@data["content_urls"]["desktop"]["page"]
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module WikipediaRestClient
|
2
|
+
|
3
|
+
# Base URL of the Wikipedia REST API.
|
4
|
+
BASE_URL = "https://en.wikipedia.org/api/rest_v1"
|
5
|
+
# URL parameters that are used to fetch the page content.
|
6
|
+
PAGE_URL = "/page/summary/"
|
7
|
+
# URL parameters that are used to fetch random page from Wikipedia.
|
8
|
+
RANDOM_PAGE_URL = "/page/random/summary"
|
9
|
+
# URL parameters that are used to get featured articles.
|
10
|
+
FEATURED_ARTICLE = "/feed/featured/"
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "wikipedia_rest_client/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "wikipedia_rest_client"
|
7
|
+
spec.version = WikipediaRestClient::VERSION
|
8
|
+
spec.authors = ["Balaji"]
|
9
|
+
spec.email = ["balaji030698@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{This is ruby gem for getting Wikipedia contents.}
|
12
|
+
spec.description = %q{By using this gem, we can get Wikipedia page contents, today's featured article, and picture of the day from Wikipedia.}
|
13
|
+
spec.homepage = "https://github.com/Balaji-Ramasubramanian/wikipedia_rest_client.git"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = ['lib/wikipedia_rest_client/version.rb',
|
16
|
+
'lib/wikipedia_rest_client/utils.rb',
|
17
|
+
'lib/wikipedia_rest_client/page.rb',
|
18
|
+
'lib/wikipedia_rest_client/featured_article.rb',
|
19
|
+
'lib/wikipedia_rest_client/image_of_the_day.rb'
|
20
|
+
]
|
21
|
+
# spec.files = Dir['lib/**/*.rb']
|
22
|
+
|
23
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
24
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
25
|
+
if spec.respond_to?(:metadata)
|
26
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
27
|
+
else
|
28
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
29
|
+
"public gem pushes."
|
30
|
+
end
|
31
|
+
|
32
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
33
|
+
f.match(%r{^(test|spec|features)/})
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_dependency "json", "~> 2.0.2"
|
43
|
+
spec.add_dependency "httparty", "~> 0.15.6"
|
44
|
+
spec.add_dependency 'nokogiri', '>= 1.6.8'
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wikipedia_rest_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Balaji
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.15.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.15.6
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nokogiri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.6.8
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.6.8
|
97
|
+
description: By using this gem, we can get Wikipedia page contents, today's featured
|
98
|
+
article, and picture of the day from Wikipedia.
|
99
|
+
email:
|
100
|
+
- balaji030698@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".DS_Store"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/setup
|
117
|
+
- lib/wikipedia_rest_client.rb
|
118
|
+
- lib/wikipedia_rest_client/featured_article.rb
|
119
|
+
- lib/wikipedia_rest_client/image_of_the_day.rb
|
120
|
+
- lib/wikipedia_rest_client/page.rb
|
121
|
+
- lib/wikipedia_rest_client/utils.rb
|
122
|
+
- lib/wikipedia_rest_client/version.rb
|
123
|
+
- wikipedia_rest_client.gemspec
|
124
|
+
homepage: https://github.com/Balaji-Ramasubramanian/wikipedia_rest_client.git
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata:
|
128
|
+
allowed_push_host: https://rubygems.org
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.7.2
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: This is ruby gem for getting Wikipedia contents.
|
149
|
+
test_files: []
|