api_access 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_access/version.rb +1 -1
- data/lib/api_access.rb +9 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0391303d1bec824cf17ccb708840bc71ac964fe
|
4
|
+
data.tar.gz: 8507a8843b1e3c0340b4dc1fc7db68f0de979363
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d129c01eacb0e9cb761099f3825a2876879a4fe89f9c8abbaa9a67f6768e6cf875b515893240710515a75d277ce2ef9ea9b33038726d0580733e36d709d6f398
|
7
|
+
data.tar.gz: 05653cad70f6fc05d20f6303274b5ed857a5bab834bd880e31bd0b2f9df3edf17696e28389662616c99f9b6ad5e64aa21855de1e067dac92f7780f9272f676c1
|
data/lib/api_access/version.rb
CHANGED
data/lib/api_access.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
require "api_access/version"
|
2
1
|
require 'net/http'
|
3
2
|
require 'net/https'
|
4
3
|
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# require "api_access/version"
|
5
7
|
|
6
8
|
class ApiAccess
|
7
9
|
class << self
|
8
|
-
def get(url, get_params)
|
10
|
+
def get(url, get_params = {})
|
9
11
|
request(url,get_params,'get')
|
10
12
|
end
|
11
13
|
|
12
|
-
def post(url, post_params)
|
14
|
+
def post(url, post_params = {})
|
13
15
|
request(url,post_params,'post')
|
14
16
|
end
|
15
17
|
|
16
18
|
# assume get json data
|
17
19
|
def request(url,request_params,method = 'get')
|
18
20
|
uri = URI(url)
|
19
|
-
|
20
|
-
http.use_ssl = (uri.scheme == 'https')
|
21
|
+
klass = (uri.scheme == 'https' ? Net::HTTPS : Net::HTTP)
|
21
22
|
if method == 'get'
|
22
|
-
query = URI.encode_www_form(request_params)
|
23
|
-
response =
|
23
|
+
uri.query = (uri.query.nil? : '' ? (uri.query + "&")) + URI.encode_www_form(request_params)
|
24
|
+
response = klass.get_response(uri)
|
24
25
|
else
|
25
|
-
response =
|
26
|
+
response = klass.post_form(uri, request_params)
|
26
27
|
end
|
27
28
|
if response.kind_of? Net::HTTPSuccess
|
28
29
|
JSON.parse(response.body)
|