Skip to content

Commit

Permalink
Switches httparty with requests
Browse files Browse the repository at this point in the history
Updates API endpoint
  • Loading branch information
picandocodigo committed Nov 25, 2014
1 parent f5f5827 commit 84b4bd4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ gem 'sinatra'
gem 'sinatra-r18n'
gem 'haml'
gem 'sass'
gem 'httparty'
gem 'requests'
8 changes: 2 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ GEM
remote: https://rubygems.org/
specs:
haml (3.1.4)
httparty (0.8.1)
multi_json
multi_xml
multi_json (1.2.0)
multi_xml (0.4.1)
r18n-core (0.4.14)
rack (1.4.1)
rack-protection (1.2.0)
rack
requests (1.0.0)
sass (3.2.3)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
Expand All @@ -26,8 +22,8 @@ PLATFORMS

DEPENDENCIES
haml
httparty
rack
requests
sass
sinatra
sinatra-r18n
2 changes: 1 addition & 1 deletion data/api_info.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
api_host: http://mnav.heroku.com/
api_host: http://mnav.herokuapp.com/
11 changes: 4 additions & 7 deletions lib/mnav_service.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require 'yaml'
require 'httparty'
require 'requests'

# Public - Generic class for http access on the MNAV API
class MNAVService
include HTTParty
format :json

# Public - Constructor
#
# Get the base_uri from api_info.yaml
Expand All @@ -21,10 +18,10 @@ def initialize
def get_data(url, query = nil)
url = "#{@base_uri}/#{url}/"
if(query)
data = HTTParty.get(url, :query => query)
data = Requests.request("GET", url, params: query )
else
data = HTTParty.get(url)
data = Requests.request("GET", url)
end
return data.parsed_response
return JSON.parse data.body
end
end
26 changes: 16 additions & 10 deletions lib/wikipedia_service.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
require 'httparty'
require 'requests'

# Public - Access Wikipedia API
module WikipediaService
include HTTParty
base_uri "http://es.wikipedia.org/w/api.php"

#Wikipedia requires us to identify ourselves:
headers 'User-agent' =>
"MNAV Open Data front-end - https://github.com/picandocodigo/mnav-opendata-front-end"

# Public - Search wikipedia articles with this search string
#
# term - search String
def self.search(term)
data = get("?action=query&list=search&format=json&srsearch=#{term}").parsed_response
def self.search( term )
base_uri = "http://es.wikipedia.org/w/api.php"
params = {
action: "query",
list: "search",
format: "json",
srsearch: term
}
#Wikipedia requires us to identify ourselves:
header = {
'User-agent' =>
"MNAV Open Data front-end - https://github.com/picandocodigo/mnav-opendata-front-end"
}
data = Requests.get( base_uri, headers: header, params: params )
require 'byebug'; byebug
return data["query"]['search']
end

Expand Down

0 comments on commit 84b4bd4

Please sign in to comment.