oja 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -0
- data/lib/oja/cli.rb +55 -0
- data/lib/oja/mock.rb +1 -1
- data/lib/oja/option_parser.rb +36 -0
- data/lib/oja/receipt.rb +5 -10
- data/lib/oja.rb +5 -0
- metadata +27 -39
    
        data/README.md
    CHANGED
    
    | @@ -13,6 +13,7 @@ iOS and Mac application receive Receipts when handling purchases from the App St | |
| 13 13 | 
             
                response = Oja.verify(:data => data)
         | 
| 14 14 | 
             
                if response.active?
         | 
| 15 15 | 
             
                  # Whatever you need to do
         | 
| 16 | 
            +
                  p response.receipt_data
         | 
| 16 17 | 
             
                elsif response.inactive?
         | 
| 17 18 | 
             
                  # The receipt probably expired
         | 
| 18 19 | 
             
                else
         | 
    
        data/lib/oja/cli.rb
    ADDED
    
    | @@ -0,0 +1,55 @@ | |
| 1 | 
            +
            require 'oja/option_parser'
         | 
| 2 | 
            +
            require 'oja'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Oja
         | 
| 5 | 
            +
              class CLI
         | 
| 6 | 
            +
                def initialize(argv)
         | 
| 7 | 
            +
                  @options, @argv = Oja::OptionParser.parse(argv)
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def usage
         | 
| 11 | 
            +
                  puts "Usage: #{File.basename($0)} <receipt-file>"
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def receipt_filename
         | 
| 15 | 
            +
                  @argv[0]
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def print_receipt_details(receipt_data)
         | 
| 19 | 
            +
                  receipt_data.each do |key, value|
         | 
| 20 | 
            +
                    puts "#{key}: #{value}"
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def check_receipt
         | 
| 25 | 
            +
                  if response = Oja.verify_filename(receipt_filename)
         | 
| 26 | 
            +
                    if response.active?
         | 
| 27 | 
            +
                      puts "[!] Receipt appears to be valid and active"
         | 
| 28 | 
            +
                      puts
         | 
| 29 | 
            +
                      print_receipt_details(response.receipt_data)
         | 
| 30 | 
            +
                    else
         | 
| 31 | 
            +
                      puts "[!] Receipt is invalid (#{response.humanized_status})"
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
                  else
         | 
| 34 | 
            +
                    log("[!] Apple Store seems inacessible")
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                def run
         | 
| 39 | 
            +
                  if receipt_filename
         | 
| 40 | 
            +
                    check_receipt
         | 
| 41 | 
            +
                  else
         | 
| 42 | 
            +
                    usage
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                def log(message)
         | 
| 47 | 
            +
                  $stderr.puts(message)
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                def self.run(argv)
         | 
| 51 | 
            +
                  cli = new(argv.dup)
         | 
| 52 | 
            +
                  cli.run
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
            end
         | 
    
        data/lib/oja/mock.rb
    CHANGED
    
    
| @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            module Oja
         | 
| 2 | 
            +
              class OptionParser
         | 
| 3 | 
            +
                # Parses ARGV from a Ruby script and returns options as a hash and
         | 
| 4 | 
            +
                # arguments as a list.
         | 
| 5 | 
            +
                #
         | 
| 6 | 
            +
                #   OptionParser.parse(%w(create --username manfred)) #=>
         | 
| 7 | 
            +
                #     [{"username"=>"manfred"}, ["create"]]
         | 
| 8 | 
            +
                def self.parse(argv)
         | 
| 9 | 
            +
                  return [{},[]] if argv.empty?
         | 
| 10 | 
            +
                
         | 
| 11 | 
            +
                  options  = {}
         | 
| 12 | 
            +
                  rest     = []
         | 
| 13 | 
            +
                  switch   = nil
         | 
| 14 | 
            +
                
         | 
| 15 | 
            +
                  for value in argv
         | 
| 16 | 
            +
                    bytes = value.respond_to?(:bytes) ? value.bytes.first(2) : [value[0], value[1]]
         | 
| 17 | 
            +
                    # value is a switch
         | 
| 18 | 
            +
                    if bytes[0] == 45
         | 
| 19 | 
            +
                      switch = value.slice((bytes[1] == 45 ? 2 : 1)..-1)
         | 
| 20 | 
            +
                      options[switch] = nil
         | 
| 21 | 
            +
                    else
         | 
| 22 | 
            +
                      if switch
         | 
| 23 | 
            +
                        # we encountered another switch so this
         | 
| 24 | 
            +
                        # value belongs to the last switch
         | 
| 25 | 
            +
                        options[switch] = value
         | 
| 26 | 
            +
                        switch = nil
         | 
| 27 | 
            +
                      else
         | 
| 28 | 
            +
                        rest << value
         | 
| 29 | 
            +
                      end
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                
         | 
| 33 | 
            +
                  [options, rest]
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
            end
         | 
    
        data/lib/oja/receipt.rb
    CHANGED
    
    | @@ -2,7 +2,8 @@ require 'base64' | |
| 2 2 |  | 
| 3 3 | 
             
            module Oja
         | 
| 4 4 | 
             
              class Receipt
         | 
| 5 | 
            -
                attr_accessor : | 
| 5 | 
            +
                attr_accessor :filename
         | 
| 6 | 
            +
                attr_writer :data
         | 
| 6 7 |  | 
| 7 8 | 
             
                def initialize(attributes)
         | 
| 8 9 | 
             
                  attributes.each do |attribute, value|
         | 
| @@ -22,12 +23,12 @@ module Oja | |
| 22 23 | 
             
                  File.read(filename)
         | 
| 23 24 | 
             
                end
         | 
| 24 25 |  | 
| 25 | 
            -
                def  | 
| 26 | 
            -
                  data  | 
| 26 | 
            +
                def data
         | 
| 27 | 
            +
                  @data ||= read
         | 
| 27 28 | 
             
                end
         | 
| 28 29 |  | 
| 29 30 | 
             
                def receipt_data
         | 
| 30 | 
            -
                  Base64.encode64( | 
| 31 | 
            +
                  Base64.encode64(data)
         | 
| 31 32 | 
             
                end
         | 
| 32 33 |  | 
| 33 34 | 
             
                def to_json
         | 
| @@ -45,11 +46,5 @@ module Oja | |
| 45 46 | 
             
                    end
         | 
| 46 47 | 
             
                  end
         | 
| 47 48 | 
             
                end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                private
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                def data_or_read
         | 
| 52 | 
            -
                  data || File.read(filename)
         | 
| 53 | 
            -
                end
         | 
| 54 49 | 
             
              end
         | 
| 55 50 | 
             
            end
         | 
    
        data/lib/oja.rb
    CHANGED
    
    | @@ -3,6 +3,11 @@ require 'oja/request' | |
| 3 3 | 
             
            require 'oja/response'
         | 
| 4 4 |  | 
| 5 5 | 
             
            module Oja
         | 
| 6 | 
            +
              def self.verify(data)
         | 
| 7 | 
            +
                receipt = Oja::Receipt.new(:data => data)
         | 
| 8 | 
            +
                receipt.verify
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 6 11 | 
             
              def self.verify_filename(receipt_filename)
         | 
| 7 12 | 
             
                receipt = Oja::Receipt.new(:filename => receipt_filename)
         | 
| 8 13 | 
             
                receipt.verify
         | 
    
        metadata
    CHANGED
    
    | @@ -1,33 +1,28 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: oja
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version | 
| 4 | 
            -
               | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 | 
            -
              segments: 
         | 
| 7 | 
            -
              - 0
         | 
| 8 | 
            -
              - 1
         | 
| 9 | 
            -
              - 0
         | 
| 10 | 
            -
              version: 0.1.0
         | 
| 11 6 | 
             
            platform: ruby
         | 
| 12 | 
            -
            authors: | 
| 7 | 
            +
            authors:
         | 
| 13 8 | 
             
            - Manfred Stienstra
         | 
| 14 9 | 
             
            autorequire: 
         | 
| 15 10 | 
             
            bindir: bin
         | 
| 16 11 | 
             
            cert_chain: []
         | 
| 17 | 
            -
             | 
| 18 | 
            -
            date: 2012-08-28 00:00:00 Z
         | 
| 12 | 
            +
            date: 2012-09-18 00:00:00.000000000 Z
         | 
| 19 13 | 
             
            dependencies: []
         | 
| 14 | 
            +
            description: ! '    Oja is a Ruby client for verification of Apple Store Receipts.
         | 
| 20 15 |  | 
| 21 | 
            -
             | 
| 16 | 
            +
            '
         | 
| 22 17 | 
             
            email: manfred@fngtps.com
         | 
| 23 18 | 
             
            executables: []
         | 
| 24 | 
            -
             | 
| 25 19 | 
             
            extensions: []
         | 
| 26 | 
            -
             | 
| 27 | 
            -
            extra_rdoc_files: 
         | 
| 20 | 
            +
            extra_rdoc_files:
         | 
| 28 21 | 
             
            - LICENSE
         | 
| 29 | 
            -
            files: | 
| 22 | 
            +
            files:
         | 
| 23 | 
            +
            - lib/oja/cli.rb
         | 
| 30 24 | 
             
            - lib/oja/mock.rb
         | 
| 25 | 
            +
            - lib/oja/option_parser.rb
         | 
| 31 26 | 
             
            - lib/oja/receipt.rb
         | 
| 32 27 | 
             
            - lib/oja/request.rb
         | 
| 33 28 | 
             
            - lib/oja/response.rb
         | 
| @@ -36,36 +31,29 @@ files: | |
| 36 31 | 
             
            - README.md
         | 
| 37 32 | 
             
            homepage: 
         | 
| 38 33 | 
             
            licenses: []
         | 
| 39 | 
            -
             | 
| 40 34 | 
             
            post_install_message: 
         | 
| 41 | 
            -
            rdoc_options: | 
| 35 | 
            +
            rdoc_options:
         | 
| 42 36 | 
             
            - --charset=utf-8
         | 
| 43 | 
            -
            require_paths: | 
| 37 | 
            +
            require_paths:
         | 
| 44 38 | 
             
            - lib
         | 
| 45 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement | 
| 39 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 46 40 | 
             
              none: false
         | 
| 47 | 
            -
              requirements: | 
| 48 | 
            -
              - -  | 
| 49 | 
            -
                - !ruby/object:Gem::Version | 
| 50 | 
            -
                   | 
| 51 | 
            -
             | 
| 52 | 
            -
                  - 0
         | 
| 53 | 
            -
                  version: "0"
         | 
| 54 | 
            -
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 41 | 
            +
              requirements:
         | 
| 42 | 
            +
              - - ! '>='
         | 
| 43 | 
            +
                - !ruby/object:Gem::Version
         | 
| 44 | 
            +
                  version: '0'
         | 
| 45 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 55 46 | 
             
              none: false
         | 
| 56 | 
            -
              requirements: | 
| 57 | 
            -
              - -  | 
| 58 | 
            -
                - !ruby/object:Gem::Version | 
| 59 | 
            -
                   | 
| 60 | 
            -
                  segments: 
         | 
| 61 | 
            -
                  - 0
         | 
| 62 | 
            -
                  version: "0"
         | 
| 47 | 
            +
              requirements:
         | 
| 48 | 
            +
              - - ! '>='
         | 
| 49 | 
            +
                - !ruby/object:Gem::Version
         | 
| 50 | 
            +
                  version: '0'
         | 
| 63 51 | 
             
            requirements: []
         | 
| 64 | 
            -
             | 
| 65 52 | 
             
            rubyforge_project: 
         | 
| 66 | 
            -
            rubygems_version: 1.8. | 
| 53 | 
            +
            rubygems_version: 1.8.23
         | 
| 67 54 | 
             
            signing_key: 
         | 
| 68 55 | 
             
            specification_version: 3
         | 
| 69 | 
            -
            summary: iOS and Mac application receive Receipts when handling purchases from the | 
| 56 | 
            +
            summary: iOS and Mac application receive Receipts when handling purchases from the
         | 
| 57 | 
            +
              App Store. Before authorizing access to in-app content, these applications need
         | 
| 58 | 
            +
              to verify the receipt with Apple. Oja helps you check the Receipt's status.
         | 
| 70 59 | 
             
            test_files: []
         | 
| 71 | 
            -
             |