Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[f] converting to net/https

  • Loading branch information...
commit 0f6aea106629a70a9ba7b9926f4abe40632bf1b5 1 parent 303027f
@jjeffus authored
Showing with 3,418 additions and 10 deletions.
  1. +3,376 −0 config/cacert.pem
  2. +41 −9 lib/SaasySimple.rb
  3. +1 −1  lib/SaasySimple/version.rb
View
3,376 config/cacert.pem
3,376 additions, 0 deletions not shown
View
50 lib/SaasySimple.rb
@@ -1,4 +1,6 @@
require "SaasySimple/engine"
+require 'net/https'
+require 'uri'
module SaasySimple
def self.config(&block)
@@ -12,21 +14,51 @@ def self.config(&block)
def self.subscription(user)
s = {}
if user.status == 'active'
- x = open(
- "https://api.fastspring.com/company/" +
- SaasySimple.config.store_id +
- "/subscription/" + user.token +
- "?user=" + SaasySimple.config.username +
- "&pass=" + SaasySimple.config.password
- )
- xml = x.read
- nok = Nokogiri::XML(xml)
+ url = "https://api.fastspring.com/company/" +
+ SaasySimple.config.store_id +
+ "/subscription/" + user.token +
+ "?user=" + SaasySimple.config.username +
+ "&pass=" + SaasySimple.config.password
+ uri = URI.parse(url)
+ http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = true
+ http.ca_file = SaasySimple::Engine.root.join("config/cacert.pem").to_s
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ request = Net::HTTP::Get.new(uri.request_uri)
+ response = http.request(request)
+ xml = response.body
+ nok = Nokogiri::XML(xml)
s['nextPeriodDate'] = nok.xpath("//nextPeriodDate").text if nok.xpath("//nextPeriodDate")
s['status'] = nok.xpath("//status").text if nok.xpath("//status")
s['customerUrl'] = nok.xpath("//customerUrl").text if nok.xpath("//customerUrl")
end
s
end
+
+ def self.cancel(user)
+ s = {}
+ if user.status == 'active'
+ url = "https://api.fastspring.com/company/" +
+ SaasySimple.config.store_id +
+ "/subscription/" + user.token +
+ "?user=" + SaasySimple.config.username +
+ "&pass=" + SaasySimple.config.password
+ uri = URI.parse(url)
+ http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = true
+ http.ca_file = SaasySimple::Engine.root.join("config/cacert.pem").to_s
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ request = Net::HTTP::Delete.new(uri.request_uri)
+ response = http.request(request)
+ xml = response.body
+ nok = Nokogiri::XML(xml)
+ s['nextPeriodDate'] = nok.xpath("//nextPeriodDate").text if nok.xpath("//nextPeriodDate")
+ s['status'] = nok.xpath("//status").text if nok.xpath("//status")
+ s['customerUrl'] = nok.xpath("//customerUrl").text if nok.xpath("//customerUrl")
+ end
+ s
+ end
+
def self.signup(user)
"#{SaasySimple.config.url}?referrer=#{user.id}"
end
View
2  lib/SaasySimple/version.rb
@@ -1,3 +1,3 @@
module SaasySimple
- VERSION = "0.1.0"
+ VERSION = "0.1.1"
end
Please sign in to comment.
Something went wrong with that request. Please try again.