cashstar 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/Gemfile +1 -3
  2. data/cashstar.gemspec +5 -2
  3. data/lib/.DS_Store +0 -0
  4. data/lib/cashstar.rb +23 -20
  5. data/lib/cashstar/.DS_Store +0 -0
  6. data/lib/cashstar/api.rb +24 -0
  7. data/lib/cashstar/authentication.rb +23 -0
  8. data/lib/cashstar/client.rb +26 -0
  9. data/lib/cashstar/client/catalog.rb +12 -0
  10. data/lib/cashstar/client/faceplates.rb +14 -0
  11. data/lib/cashstar/client/gift_card.rb +31 -0
  12. data/lib/cashstar/client/merchants.rb +15 -0
  13. data/lib/cashstar/client/order.rb +26 -0
  14. data/lib/cashstar/configuration.rb +72 -0
  15. data/lib/cashstar/connection.rb +42 -0
  16. data/lib/cashstar/error.rb +36 -0
  17. data/lib/cashstar/request.rb +43 -0
  18. data/lib/cashstar/version.rb +1 -1
  19. data/lib/faraday/request/basic_auth.rb +17 -0
  20. data/lib/faraday/request/gateway.rb +18 -0
  21. data/lib/faraday/response/raise_http_4xx.rb +45 -0
  22. data/lib/faraday/response/raise_http_5xx.rb +24 -0
  23. metadata +92 -70
  24. data/lib/cashstar/entities.rb +0 -20
  25. data/lib/cashstar/entities/base.rb +0 -19
  26. data/lib/cashstar/entities/catalog.rb +0 -18
  27. data/lib/cashstar/entities/credit_card.rb +0 -10
  28. data/lib/cashstar/entities/error.rb +0 -0
  29. data/lib/cashstar/entities/faceplate.rb +0 -25
  30. data/lib/cashstar/entities/gift_certificate.rb +0 -21
  31. data/lib/cashstar/entities/gift_certificate_delivery.rb +0 -13
  32. data/lib/cashstar/entities/gift_certificate_message.rb +0 -11
  33. data/lib/cashstar/entities/merchant.rb +0 -31
  34. data/lib/cashstar/entities/order.rb +0 -39
  35. data/lib/cashstar/entities/payment.rb +0 -10
  36. data/lib/cashstar/entities/purchaser.rb +0 -10
  37. data/lib/cashstar/entities/purchaser_account.rb +0 -10
  38. data/lib/cashstar/entities/web_session.rb +0 -10
data/Gemfile CHANGED
@@ -2,6 +2,4 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in cashstar.gemspec
4
4
  gemspec
5
- gem "activesupport"
6
- gem "json"
7
- gem "rest-client"
5
+
@@ -3,6 +3,11 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "cashstar/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
+ s.add_dependency 'hashie', '~> 1.1.0'
7
+ s.add_dependency 'faraday', '~> 0.7.4'
8
+ s.add_dependency 'faraday_middleware', '~> 0.7.0'
9
+ s.add_dependency 'multi_json', '~> 1.0.0'
10
+ s.add_dependency 'multi_xml', '~> 0.4.0'
6
11
  s.name = "cashstar"
7
12
  s.version = Cashstar::VERSION
8
13
  s.platform = Gem::Platform::RUBY
@@ -11,8 +16,6 @@ Gem::Specification.new do |s|
11
16
  s.homepage = "http://www.cashstar.com"
12
17
  s.summary = %q{Ruby Bindings for the CashStar API}
13
18
  s.description = %q{CashStar's API provides a simple interface for purchasing and issuing electronic gift cards from a variety of brands}
14
-
15
- s.add_dependency('rest-client', ">=1.6.1")
16
19
  s.rubyforge_project = "cashstar"
17
20
 
18
21
  s.files = `git ls-files`.split("\n")
Binary file
@@ -1,24 +1,27 @@
1
-
2
-
3
-
4
- require 'active_support'
5
- require 'active_support/core_ext/string/inflections'
6
- require 'active_support/core_ext/hash/indifferent_access'
7
- require 'active_support/core_ext/hash/conversions'
8
- require 'active_support/core_ext/class/inheritable_attributes'
9
- require 'active_support/core_ext/class/attribute_accessors'
10
- require 'active_support/core_ext/class/delegating_attributes'
11
- require 'active_support/core_ext/module/attribute_accessors'
12
- require 'active_support/core_ext/kernel/requires'
13
- require 'active_support/base64'
14
- require 'active_support/secure_random'
15
- require 'rest_client'
16
-
1
+ require 'cashstar/api'
2
+ require 'cashstar/client'
3
+ require 'cashstar/configuration'
4
+ require 'cashstar/error'
17
5
 
18
6
 
19
7
  module Cashstar
20
- # Your code goes here...
8
+ extend Configuration
9
+ class << self
10
+ # Alias for Cashstar::Client.new
11
+ #
12
+ # @return [Cashstar::Client]
13
+ def new(options={})
14
+ Cashstar::Client.new(options)
15
+ end
16
+
17
+ # Delegate to Cashstar::Client
18
+ def method_missing(method, *args, &block)
19
+ return super unless new.respond_to?(method)
20
+ new.send(method, *args, &block)
21
+ end
22
+
23
+ def respond_to?(method, include_private = false)
24
+ new.respond_to?(method, include_private) || super(method, include_private)
25
+ end
26
+ end
21
27
  end
22
-
23
-
24
- require "cashstar/entities"
Binary file
@@ -0,0 +1,24 @@
1
+ require 'cashstar/authentication'
2
+ require 'cashstar/configuration'
3
+ require 'cashstar/connection'
4
+ require 'cashstar/request'
5
+
6
+ module Cashstar
7
+ # @private
8
+ class API
9
+ include Connection
10
+ include Request
11
+ include Authentication
12
+
13
+ # @private
14
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
15
+
16
+ # Creates a new API
17
+ def initialize(options={})
18
+ options = Cashstar.options.merge(options)
19
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
20
+ send("#{key}=", options[key])
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module Cashstar
2
+ # @private
3
+ module Authentication
4
+ private
5
+
6
+ # Authentication hash
7
+ #
8
+ # @return [Hash]
9
+ def authentication
10
+ {
11
+ :username => username,
12
+ :password => password,
13
+ }
14
+ end
15
+
16
+ # Check whether user is authenticated
17
+ #
18
+ # @return [Boolean]
19
+ def authenticated?
20
+ authentication.values.all?
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ module Cashstar
2
+ # Wrapper for the CashStar REST API
3
+ #
4
+ # @note All methods have been separated into modules
5
+ class Client < API
6
+ # Require client method modules after initializing the Client class in
7
+ # order to avoid a superclass mismatch error, allowing those modules to be
8
+ # Client-namespaced.
9
+ require 'cashstar/client/merchants'
10
+ require 'cashstar/client/catalog'
11
+ require 'cashstar/client/faceplates'
12
+ require 'cashstar/client/order'
13
+ require 'cashstar/client/gift_card'
14
+
15
+
16
+ alias :api_endpoint :endpoint
17
+
18
+ include Cashstar::Client::Merchants
19
+ include Cashstar::Client::Faceplates
20
+ include Cashstar::Client::Catalog
21
+ include Cashstar::Client::OrderMethods
22
+
23
+
24
+
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module Cashstar
2
+ class Client
3
+ # Defines methods related to a Cashstar Order
4
+ module Catalog
5
+
6
+ def catalog(merchant_code)
7
+ response = get("/v2/merchant/#{merchant_code}/catalog/")
8
+ format.to_s.downcase == 'xml' ? response['catalog'] : response['catalog']
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Cashstar
2
+ class Client
3
+ # Defines methods related to a Cashstar Order
4
+ module Faceplates
5
+
6
+ def faceplates(merchant_code)
7
+ response = get("/v2/merchant/#{merchant_code}/faceplate/")
8
+ format.to_s.downcase == 'xml' ? response['merchant'] : response['faceplates']['faceplate']
9
+ end
10
+
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ require 'hashie'
2
+
3
+ module Cashstar
4
+ class Client
5
+ # Defines methods related to a Cashstar Order
6
+ class GiftCard < Hashie::Dash
7
+ property :merchant_code, :required => true
8
+ property :initial_balance, :required => true
9
+ property :currency, :default => 'USD'
10
+ property :challenge
11
+ property :challenge_description
12
+ property :delivery
13
+ property :message
14
+
15
+
16
+ end
17
+
18
+ class Delivery < Hashie::Dash
19
+ property :delivered_by, :default => 'CASHSTAR'
20
+ property :method
21
+ property :target
22
+ property :scheduled
23
+ end
24
+
25
+ class Message < Hashie::Dash
26
+ property :from
27
+ property :to
28
+ property :body
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ module Cashstar
2
+ class Client
3
+ # Defines methods related to Cashstar merchants
4
+ module Merchants
5
+
6
+
7
+ def merchants
8
+ response = get("/v2/merchant/")
9
+ format.to_s.downcase == 'xml' ? response['merchant'] : response['merchants']['merchant']
10
+ end
11
+
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'hashie'
2
+
3
+
4
+ module Cashstar
5
+ class Client
6
+ module OrderMethods
7
+ def issue(order)
8
+ response = post("/v2/order/", order.to_json)
9
+ format.to_s.downcase == 'xml' ? response['order'] : response['order']
10
+ end
11
+ end
12
+
13
+ # Defines methods related to a Cashstar Order
14
+ class Order < Hashie::Dash
15
+ property :audit_number, :required => true
16
+ property :gift_card, :required => true
17
+ property :payment, :default => nil
18
+
19
+ def to_json()
20
+ "{ \"order\" : { \"audit_number\" : \"#{self.audit_number}\", \"egc\" : #{self.gift_card.to_json}}}"
21
+ end
22
+ end
23
+
24
+
25
+ end
26
+ end
@@ -0,0 +1,72 @@
1
+ require 'cashstar/version'
2
+
3
+ module Cashstar
4
+ # Defines constants and methods related to configuration
5
+ module Configuration
6
+ # An array of valid keys in the options hash when configuring a {Cashstar::API}
7
+ VALID_OPTIONS_KEYS = [
8
+ :username,
9
+ :password,
10
+ :endpoint,
11
+ :format,
12
+ :user_agent,
13
+ :adapter,
14
+ :faraday_options].freeze
15
+
16
+ # The adapter that will be used to connect if none is set
17
+ DEFAULT_ADAPTER = :net_http
18
+
19
+ # By default, don't set a username
20
+ DEFAULT_USERNAME = nil
21
+
22
+ # By default, don't set a password
23
+ DEFAULT_PASSWORD = nil
24
+
25
+ # The endpoint that will be used to connect if none is set
26
+ #
27
+ # @note This is configurable in case you want to connect to CashStar's test environment at https://api-semiprod.cashstar.com
28
+ DEFAULT_ENDPOINT = 'https://api-semiprod.cashstar.com'.freeze
29
+
30
+ # The response format appended to the path and sent in the 'Accept' header if none is set
31
+ #
32
+ # @note JSON is preferred over XML because it is more concise and faster to parse.
33
+ DEFAULT_FORMAT = :json
34
+
35
+ # The value sent in the 'User-Agent' header if none is set
36
+ DEFAULT_USER_AGENT = "CashStar Ruby Gem #{Cashstar::VERSION}".freeze
37
+
38
+ DEFAULT_FARADAY_OPTIONS = {}.freeze
39
+
40
+ # @private
41
+ attr_accessor *VALID_OPTIONS_KEYS
42
+
43
+ # When this module is extended, set all configuration options to their default values
44
+ def self.extended(base)
45
+ base.reset
46
+ end
47
+
48
+ # Convenience method to allow configuration options to be set in a block
49
+ def configure
50
+ yield self
51
+ end
52
+
53
+ # Create a hash of options and their values
54
+ def options
55
+ options = {}
56
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
57
+ options
58
+ end
59
+
60
+ # Reset all configuration options to defaults
61
+ def reset
62
+ self.adapter = DEFAULT_ADAPTER
63
+ self.username = DEFAULT_USERNAME
64
+ self.password = DEFAULT_PASSWORD
65
+ self.endpoint = DEFAULT_ENDPOINT
66
+ self.format = DEFAULT_FORMAT
67
+ self.user_agent = DEFAULT_USER_AGENT
68
+ self.faraday_options = DEFAULT_FARADAY_OPTIONS
69
+ self
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,42 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/request/gateway'
3
+ require 'faraday/request/basic_auth'
4
+ require 'faraday/response/raise_http_4xx'
5
+ require 'faraday/response/raise_http_5xx'
6
+
7
+ module Cashstar
8
+ # @private
9
+ module Connection
10
+ private
11
+
12
+ def connection(options={})
13
+ merged_options = faraday_options.merge({
14
+ :headers => {
15
+ 'Accept' => "application/json",
16
+ 'User-Agent' => user_agent,
17
+ 'Content-Type' => "application/json"
18
+ },
19
+ :ssl => {:verify => false},
20
+ :url => options.fetch(:endpoint, api_endpoint)
21
+ })
22
+
23
+ faraday = Faraday.new(merged_options) do |builder|
24
+ builder.use Faraday::Request::BasicAuth, authentication if authenticated?
25
+ builder.use Faraday::Request::UrlEncoded
26
+ builder.use Faraday::Response::RaiseHttp4xx
27
+ unless options[:raw]
28
+ case options.fetch(:format, format).to_s.downcase
29
+ when 'json'
30
+ builder.use Faraday::Response::Mashify
31
+ builder.use Faraday::Response::ParseJson
32
+ when 'xml'
33
+ builder.use Faraday::Response::Mashify
34
+ builder.use Faraday::Response::ParseXml
35
+ end
36
+ end
37
+ builder.use Faraday::Response::RaiseHttp5xx
38
+ builder.adapter(adapter)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,36 @@
1
+ module Cashstar
2
+ # Custom error class for rescuing from all Cashstar errors
3
+ class Error < StandardError
4
+ attr_reader :http_headers
5
+
6
+ def initialize(message, http_headers)
7
+ @http_headers = Hash[http_headers]
8
+ super message
9
+ end
10
+
11
+ end
12
+
13
+ # Raised when Cashstar returns the HTTP status code 400
14
+ class BadRequest < Error; end
15
+
16
+ # Raised when Cashstar returns the HTTP status code 401
17
+ class Unauthorized < Error; end
18
+
19
+ # Raised when Cashstar returns the HTTP status code 403
20
+ class Forbidden < Error; end
21
+
22
+ # Raised when Cashstar returns the HTTP status code 404
23
+ class NotFound < Error; end
24
+
25
+ # Raised when Cashstar returns the HTTP status code 406
26
+ class NotAcceptable < Error; end
27
+
28
+ # Raised when Cashstar returns the HTTP status code 500
29
+ class InternalServerError < Error; end
30
+
31
+ # Raised when Cashstar returns the HTTP status code 502
32
+ class BadGateway < Error; end
33
+
34
+ # Raised when Cashstar returns the HTTP status code 503
35
+ class ServiceUnavailable < Error; end
36
+ end
@@ -0,0 +1,43 @@
1
+ module Cashstar
2
+ # Defines HTTP request methods
3
+ module Request
4
+ # Perform an HTTP GET request
5
+ def get(path, params={}, options={})
6
+ request(:get, path, params, options)
7
+ end
8
+
9
+ def post(path, params={}, options={})
10
+ request(:post, path, params, options)
11
+ end
12
+
13
+ # Perform an HTTP PUT request
14
+ def put(path, params={}, options={})
15
+ request(:put, path, params, options)
16
+ end
17
+
18
+ # Perform an HTTP DELETE request
19
+ def delete(path, params={}, options={})
20
+ request(:delete, path, params, options)
21
+ end
22
+
23
+ private
24
+
25
+ # Perform an HTTP request
26
+ def request(method, path, params, options)
27
+ response = connection(options).send(method) do |request|
28
+ case method.to_sym
29
+ when :get, :delete
30
+ request.url(path, params)
31
+ when :post, :put
32
+ request.path = path
33
+ request.body = params unless params.empty?
34
+ end
35
+ end
36
+ options[:raw] ? response : response.body
37
+ end
38
+
39
+ def formatted_path(path, options={})
40
+ #[path, options.fetch(:format, format)].compact.join('.')
41
+ end
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Cashstar
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,17 @@
1
+ require 'faraday'
2
+
3
+ module Faraday
4
+ class Request::BasicAuth < Faraday::Middleware
5
+ require 'base64'
6
+
7
+ def call(env)
8
+ header = Base64.encode64("#{@options[:username]}:#{@options[:password]}")
9
+ env[:request_headers]['Authorization'] = "Basic #{header.to_s}"
10
+ @app.call(env)
11
+ end
12
+
13
+ def initialize(app, options)
14
+ @app, @options = app, options
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Request::Gateway < Faraday::Middleware
7
+ def call(env)
8
+ url = env[:url].dup
9
+ url.host = @gateway
10
+ env[:url] = url
11
+ @app.call(env)
12
+ end
13
+
14
+ def initialize(app, gateway)
15
+ @app, @gateway = app, gateway
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Response::RaiseHttp4xx < Response::Middleware
7
+ def on_complete(env)
8
+ case env[:status].to_i
9
+ when 400
10
+ raise Cashstar::BadRequest.new(error_message(env), env[:response_headers])
11
+ when 401
12
+ raise Cashstar::Unauthorized.new(error_message(env), env[:response_headers])
13
+ when 403
14
+ raise Cashstar::Forbidden.new(error_message(env), env[:response_headers])
15
+ when 404
16
+ raise Cashstar::NotFound.new(error_message(env), env[:response_headers])
17
+ when 406
18
+ raise Cashstar::NotAcceptable.new(error_message(env), env[:response_headers])
19
+ when 420
20
+ raise Cashstar::EnhanceYourCalm.new(error_message(env), env[:response_headers])
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def error_message(env)
27
+ "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}"
28
+ end
29
+
30
+ def error_body(body)
31
+ if body.nil?
32
+ nil
33
+ elsif body['error']
34
+ ": #{body['error']}"
35
+ elsif body['errors']
36
+ first = Array(body['errors']).first
37
+ if first.kind_of? Hash
38
+ ": #{first['message'].chomp}"
39
+ else
40
+ ": #{first.chomp}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Response::RaiseHttp5xx < Response::Middleware
7
+ def on_complete(env)
8
+ case env[:status].to_i
9
+ when 500
10
+ raise Cashstar::InternalServerError.new(error_message(env, "Something is technically wrong."), env[:response_headers])
11
+ when 502
12
+ raise Cashstar::BadGateway.new(error_message(env, "Cashstar is down or being upgraded."), env[:response_headers])
13
+ when 503
14
+ raise Cashstar::ServiceUnavailable.new(error_message(env, "(__-){ Cashstar is over capacity."), env[:response_headers])
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def error_message(env, body=nil)
21
+ "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')}"
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,103 +1,125 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cashstar
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 4
10
- version: 0.0.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Charlie White
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-01 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: rest-client
12
+ date: 2011-09-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
16
+ requirement: &70287615158460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70287615158460
25
+ - !ruby/object:Gem::Dependency
26
+ name: faraday
27
+ requirement: &70287615157760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.4
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70287615157760
36
+ - !ruby/object:Gem::Dependency
37
+ name: faraday_middleware
38
+ requirement: &70287615156540 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.7.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70287615156540
47
+ - !ruby/object:Gem::Dependency
48
+ name: multi_json
49
+ requirement: &70287615155780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :runtime
23
56
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
57
+ version_requirements: *70287615155780
58
+ - !ruby/object:Gem::Dependency
59
+ name: multi_xml
60
+ requirement: &70287615155120 !ruby/object:Gem::Requirement
25
61
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 1
32
- - 6
33
- - 1
34
- version: 1.6.1
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.4.0
35
66
  type: :runtime
36
- version_requirements: *id001
37
- description: CashStar's API provides a simple interface for purchasing and issuing electronic gift cards from a variety of brands
38
- email:
67
+ prerelease: false
68
+ version_requirements: *70287615155120
69
+ description: CashStar's API provides a simple interface for purchasing and issuing
70
+ electronic gift cards from a variety of brands
71
+ email:
39
72
  - cwhite@cashstar.com
40
73
  executables: []
41
-
42
74
  extensions: []
43
-
44
75
  extra_rdoc_files: []
45
-
46
- files:
76
+ files:
47
77
  - .gitignore
48
78
  - Gemfile
49
79
  - Rakefile
50
80
  - cashstar.gemspec
81
+ - lib/.DS_Store
51
82
  - lib/cashstar.rb
52
- - lib/cashstar/entities.rb
53
- - lib/cashstar/entities/base.rb
54
- - lib/cashstar/entities/catalog.rb
55
- - lib/cashstar/entities/credit_card.rb
56
- - lib/cashstar/entities/error.rb
57
- - lib/cashstar/entities/faceplate.rb
58
- - lib/cashstar/entities/gift_certificate.rb
59
- - lib/cashstar/entities/gift_certificate_delivery.rb
60
- - lib/cashstar/entities/gift_certificate_message.rb
61
- - lib/cashstar/entities/merchant.rb
62
- - lib/cashstar/entities/order.rb
63
- - lib/cashstar/entities/payment.rb
64
- - lib/cashstar/entities/purchaser.rb
65
- - lib/cashstar/entities/purchaser_account.rb
66
- - lib/cashstar/entities/web_session.rb
83
+ - lib/cashstar/.DS_Store
84
+ - lib/cashstar/api.rb
85
+ - lib/cashstar/authentication.rb
86
+ - lib/cashstar/client.rb
87
+ - lib/cashstar/client/catalog.rb
88
+ - lib/cashstar/client/faceplates.rb
89
+ - lib/cashstar/client/gift_card.rb
90
+ - lib/cashstar/client/merchants.rb
91
+ - lib/cashstar/client/order.rb
92
+ - lib/cashstar/configuration.rb
93
+ - lib/cashstar/connection.rb
94
+ - lib/cashstar/error.rb
95
+ - lib/cashstar/request.rb
67
96
  - lib/cashstar/version.rb
68
- has_rdoc: true
97
+ - lib/faraday/request/basic_auth.rb
98
+ - lib/faraday/request/gateway.rb
99
+ - lib/faraday/response/raise_http_4xx.rb
100
+ - lib/faraday/response/raise_http_5xx.rb
69
101
  homepage: http://www.cashstar.com
70
102
  licenses: []
71
-
72
103
  post_install_message:
73
104
  rdoc_options: []
74
-
75
- require_paths:
105
+ require_paths:
76
106
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
107
+ required_ruby_version: !ruby/object:Gem::Requirement
78
108
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- hash: 3
83
- segments:
84
- - 0
85
- version: "0"
86
- required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
114
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
95
119
  requirements: []
96
-
97
120
  rubyforge_project: cashstar
98
- rubygems_version: 1.6.2
121
+ rubygems_version: 1.8.10
99
122
  signing_key:
100
123
  specification_version: 3
101
124
  summary: Ruby Bindings for the CashStar API
102
125
  test_files: []
103
-
@@ -1,20 +0,0 @@
1
- module Cashstar
2
- module Entities
3
-
4
- end
5
- end
6
-
7
- require 'cashstar/entities/base'
8
- require 'cashstar/entities/catalog'
9
- require 'cashstar/entities/credit_card'
10
- require 'cashstar/entities/error'
11
- require 'cashstar/entities/faceplate'
12
- require 'cashstar/entities/gift_certificate'
13
- require 'cashstar/entities/gift_certificate_delivery'
14
- require 'cashstar/entities/gift_certificate_message'
15
- require 'cashstar/entities/merchant'
16
- require 'cashstar/entities/order'
17
- require 'cashstar/entities/payment'
18
- require 'cashstar/entities/purchaser'
19
- require 'cashstar/entities/purchaser_account'
20
- require 'cashstar/entities/web_session'
@@ -1,19 +0,0 @@
1
- module Cashstar
2
- module Entities
3
-
4
- class Base
5
- cattr_accessor :remote_url, :headers
6
- self.remote_url = "https://petes_dad:Eghrt3gad3@api-semiprod.cashstar.com/v2"
7
- self.headers = {:accept => "application/json", :content_type => "application/json"}
8
-
9
- def initialize args
10
- args.each do |k,v|
11
- #raise "#{k} Does Not Exist" if not instance_variable_defined? "@#{k}"
12
- instance_variable_set("@#{k}", v) unless v.nil?
13
- end
14
- end
15
-
16
-
17
- end
18
- end
19
- end
@@ -1,18 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
- class Catalog < Base
5
-
6
-
7
- def self.all()
8
- json = JSON.parse RestClient.get remote_url, headers
9
- merchants = []
10
- json["merchants"]["merchant"].each do |merchant|
11
- merchants << Merchant.new(merchant["merchant_code"],merchant["name"])
12
- end
13
- return merchants
14
- end
15
-
16
- end
17
- end
18
- end
@@ -1,10 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class CreditCard < Base
6
- attr_accessor :card_type, :account_number, :security_code, :expiration_date, :first_name, :last_name, :address, :address2, :city, :state_code, :postal_code, :country_code, :phone, :email
7
-
8
- end
9
- end
10
- end
File without changes
@@ -1,25 +0,0 @@
1
- require 'json'
2
-
3
- module Cashstar
4
- module Entities
5
-
6
- class Faceplate < Base
7
-
8
- attr_accessor :faceplate_code, :name, :text_color, :thumbnail, :preview, :print
9
-
10
-
11
-
12
- def self.all(merchant_code)
13
- remote_url = self.remote_url + "/merchant/#{merchant_code}/faceplate/"
14
- json = JSON.parse RestClient.get remote_url, headers
15
- faceplates = []
16
- json["faceplates"]["faceplate"].each do |faceplate|
17
- faceplates << Faceplate.new(:faceplate_code => faceplate["faceplate_code"],:name => faceplate["name"],:text_color => faceplate["text_color"],
18
- :thumbnail => faceplate["thumbnail"], :preview => faceplate["preview"], :print => faceplate["print"])
19
- end
20
- return faceplates
21
- end
22
-
23
- end
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class GiftCertificate < Base
6
-
7
- attr_accessor :egc_code, :egc_number, :access_code, :merchant_code, :initial_balance, :current_balance, :balance_last_updated
8
- attr_accessor :balance_url, :currency, :active, :status, :url, :challenge, :challenge_description, :challenge_type, :faceplate_code
9
- attr_accessor :audit_number, :delivery, :message
10
-
11
-
12
-
13
- end
14
- end
15
- end
16
-
17
-
18
-
19
-
20
-
21
-
@@ -1,13 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class GiftCertificateDelivery < Base
6
-
7
- attr_accessor :delivered_by, :method, :target, :scheduled, :delivered, :received, :status
8
-
9
- end
10
- end
11
- end
12
-
13
-
@@ -1,11 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class GiftCertificateMessage < Base
6
-
7
- attr_accessor :from, :to, :body
8
-
9
- end
10
- end
11
- end
@@ -1,31 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class Merchant < Base
6
- attr_accessor :merchant_code, :name, :logo, :faceplates
7
-
8
-
9
- def faceplates
10
- @faceplates ||= Faceplate.all(@merchant_code)
11
- end
12
-
13
- def self.all()
14
- remote_url = self.remote_url + "/merchant/"
15
- result = RestClient.get remote_url , headers
16
- if result.code == 200
17
- json = JSON.parse result
18
- merchants = []
19
- json["merchants"]["merchant"].each do |merchant|
20
- merchants << Merchant.new(:merchant_code => merchant["merchant_code"], :name => merchant["name"])
21
- end
22
- return merchants
23
- else
24
- return result
25
- end
26
- end
27
-
28
- end
29
- end
30
- end
31
-
@@ -1,39 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class Order < Base
6
-
7
- attr_accessor :order_number, :transaction_id, :audit_number, :activation_callback_url, :egc, :payment, :response
8
-
9
- def post_json
10
- "{ \"order\" : #{self.to_json}}"
11
- end
12
-
13
- def purchase
14
- remote_url = self.remote_url + "/order/"
15
- begin
16
- result = RestClient.post remote_url, self.post_json, headers
17
- self.response = result
18
- print result.code
19
- if result.code == 201
20
- json = JSON.parse result
21
- self.order_number = json["order"]["order_number"]
22
- self.transaction_id = json["order"]["transaction_id"]
23
- self.audit_number = json["order"]["audit_number"]
24
- self.egc.url = json["order"]["egc"]["url"]
25
- self.egc.status = json["order"]["egc"]["status"]
26
- self.egc.initial_balance = json["order"]["egc"]["initial_balance"]
27
- return true
28
- else
29
- return false
30
- end
31
- rescue => e
32
- self.response = e.response
33
- return false
34
- end
35
- end
36
-
37
- end
38
- end
39
- end
@@ -1,10 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class Payment < Base
6
- attr_accessor :amount, :currency, :purchaser, :purchaser_account, :credit_card, :web_session, :mobile_app_session, :extended_cart_session
7
-
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class Purchaser < Base
6
- attr_accessor :first_name, :last_name, :phone, :email
7
-
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class PurchaserAccount < Base
6
- attr_accessor :user_id, :account_age, :days_since_last_purchase, :num_purchases, :num_disputes, :num_returns
7
-
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- require 'json'
2
- module Cashstar
3
- module Entities
4
-
5
- class WebSession < Base
6
- attr_accessor :http_headers, :javascript_enabled, :purchaser_ip, :purchaser_session_id, :purchaser_session_duration, :threatmetrix_session_id
7
-
8
- end
9
- end
10
- end