wikipedia_rest_client 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c452900722d27ada17549e2b5c55ee1b1c7ebda6325c801f645d072ac02db6f
4
- data.tar.gz: d6a092296053ccba45997df0b7d018235bcf439ea4c9ee980eb980f1dde99a1c
3
+ metadata.gz: b89100e886679d030ac8ea076c33288bc0d6191f629c30895fcea314aba699b7
4
+ data.tar.gz: 26bc7f8adfabe4138e7a19cfd1ee29566285c1f5eb3efbe9ea7f7a9c279684bd
5
5
  SHA512:
6
- metadata.gz: 0c215658d8f812a68d7f6ebe302e5936caf08445e0983e2fab32fc1e1079bdb3cb3fdf5c1e7561e061c00783c98f7ffbc7921945e8ebc2c0b78a24bb9d59354d
7
- data.tar.gz: 4b38f3542b2c1eac428b3b62cc80985384bbdeb6e5ad8d1597aa94f084e5fe8f33d28aaca245d0e91ed91910ebb96740f887f6110b4d9c4d9eee409bb3ddd4d1
6
+ metadata.gz: 7cfcdf869e16557ce31eb7ef36ec428ef77b8cc57fdad278d58da25838dae200196bd4870c8cd2ced62e57004b3e076b47d00fc12d01d5246378383f0a8e8d11
7
+ data.tar.gz: 85434dde0c555705a6dfa0ec8e10c40e6b7ab3ed32cf29a8ade343329ffaa1b92450d8550c4b69620787c77042a1b25cae3c75d2a1b294a54b6b028bf4122fb1
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .DS_Store
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wikipedia_rest_client (0.0.1)
4
+ wikipedia_rest_client (0.1.1)
5
5
  httparty (~> 0.15.6)
6
6
  json (~> 2.0.2)
7
7
  nokogiri (>= 1.6.8)
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.
@@ -23,7 +23,7 @@ module WikipediaRestClient
23
23
  @data["displaytitle"]
24
24
  end
25
25
 
26
- # Returns the namepade id of the page
26
+ # Returns the namespace id of the page
27
27
  def namespace_id
28
28
  @data["namespace"]["id"]
29
29
  end
@@ -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 = "https://en.wikipedia.org/api/rest_v1"
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.
@@ -1,4 +1,4 @@
1
1
  module WikipediaRestClient
2
2
  # Version number of the gem
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
@@ -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.0
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-25 00:00:00.000000000 Z
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