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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cda5193501757a9d743ddabd1448e4e373afcc94
4
- data.tar.gz: c0d4f8e1b917aa91fc2f81424d084f30c0a86ee0
3
+ metadata.gz: a0391303d1bec824cf17ccb708840bc71ac964fe
4
+ data.tar.gz: 8507a8843b1e3c0340b4dc1fc7db68f0de979363
5
5
  SHA512:
6
- metadata.gz: 1d08764aa7c7b63b68b354594b9f34c71377c487a2bf9dfcc68291882e440f562ba922c69a46da4a70eb813db44e662f9b09c37a13400bea71575c0b1a0d16f4
7
- data.tar.gz: c02b57eafb95f2b774dd3d114a872d687cdbf346c18354442c3719caadd3245f206543d5802b59d7ebab74e6a74ce62d17cf04dc8933617b4c8bcccb6877aa2c
6
+ metadata.gz: d129c01eacb0e9cb761099f3825a2876879a4fe89f9c8abbaa9a67f6768e6cf875b515893240710515a75d277ce2ef9ea9b33038726d0580733e36d709d6f398
7
+ data.tar.gz: 05653cad70f6fc05d20f6303274b5ed857a5bab834bd880e31bd0b2f9df3edf17696e28389662616c99f9b6ad5e64aa21855de1e067dac92f7780f9272f676c1
@@ -1,3 +1,3 @@
1
1
  class ApiAccess
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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
- http = Net::HTTP.new(uri.host,uri.port)
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 = http.get("#{uri.path}?#{query}")
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 = http.post(uri.path,URI.encode_www_form(request_params))
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_access
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - binz