mpesarb 0.3.0 → 0.3.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.
- checksums.yaml +4 -4
 - data/Gemfile.lock +15 -2
 - data/README.md +21 -3
 - data/lib/mpesa/resources/token.rb +26 -0
 - data/lib/mpesa/version.rb +1 -1
 - data/mpesa.gemspec +1 -0
 - metadata +16 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 68d96fb20a2f0f9d3f463f6bb4b0d6d1e520c20d1c11f2d2a938aaf451d4ef4e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 92017a2a811f1f6de9f233c083be65b892ebb591bbc2c392dd31aeedac9a4212
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 3c23bd5e3eb258bf86062cfbdc5bde0745617c5d6cb8f59da3927333331ab231e1c6c8d6c1296d5b342594b7cc7acb73d4f1c8c6ddc218de39389a79f58e37e6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: ded8afec648b6cd69b45d4d0b4f958c27c43dbe7b2113e939c4c4f83aaeb807dc5e8e7c2091ed609709b32673f8f47c47c28b9e80b1c166049c91ebf0f9cd56e
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,7 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            PATH
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: .
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                 
     | 
| 
      
 4 
     | 
    
         
            +
                mpesarb (0.3.0)
         
     | 
| 
      
 5 
     | 
    
         
            +
                  activesupport (>= 5.0.0)
         
     | 
| 
       5 
6 
     | 
    
         
             
                  faraday (>= 1.1)
         
     | 
| 
       6 
7 
     | 
    
         
             
                  faraday_middleware (~> 1.1)
         
     | 
| 
       7 
8 
     | 
    
         
             
                  openssl (>= 2.1)
         
     | 
| 
         @@ -9,12 +10,19 @@ PATH 
     | 
|
| 
       9 
10 
     | 
    
         
             
            GEM
         
     | 
| 
       10 
11 
     | 
    
         
             
              remote: https://rubygems.org/
         
     | 
| 
       11 
12 
     | 
    
         
             
              specs:
         
     | 
| 
      
 13 
     | 
    
         
            +
                activesupport (6.1.4)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  concurrent-ruby (~> 1.0, >= 1.0.2)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  i18n (>= 1.6, < 2)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  minitest (>= 5.1)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  tzinfo (~> 2.0)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  zeitwerk (~> 2.3)
         
     | 
| 
       12 
19 
     | 
    
         
             
                addressable (2.8.0)
         
     | 
| 
       13 
20 
     | 
    
         
             
                  public_suffix (>= 2.0.2, < 5.0)
         
     | 
| 
       14 
21 
     | 
    
         
             
                ansi (1.5.0)
         
     | 
| 
       15 
22 
     | 
    
         
             
                builder (3.2.4)
         
     | 
| 
       16 
23 
     | 
    
         
             
                byebug (11.1.3)
         
     | 
| 
       17 
24 
     | 
    
         
             
                coderay (1.1.3)
         
     | 
| 
      
 25 
     | 
    
         
            +
                concurrent-ruby (1.1.9)
         
     | 
| 
       18 
26 
     | 
    
         
             
                coveralls (0.8.23)
         
     | 
| 
       19 
27 
     | 
    
         
             
                  json (>= 1.8, < 3)
         
     | 
| 
       20 
28 
     | 
    
         
             
                  simplecov (~> 0.16.1)
         
     | 
| 
         @@ -46,6 +54,8 @@ GEM 
     | 
|
| 
       46 
54 
     | 
    
         
             
                faraday_middleware (1.1.0)
         
     | 
| 
       47 
55 
     | 
    
         
             
                  faraday (~> 1.0)
         
     | 
| 
       48 
56 
     | 
    
         
             
                hashdiff (1.0.1)
         
     | 
| 
      
 57 
     | 
    
         
            +
                i18n (1.8.10)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  concurrent-ruby (~> 1.0)
         
     | 
| 
       49 
59 
     | 
    
         
             
                json (2.5.1)
         
     | 
| 
       50 
60 
     | 
    
         
             
                method_source (1.0.0)
         
     | 
| 
       51 
61 
     | 
    
         
             
                minitest (5.14.4)
         
     | 
| 
         @@ -78,11 +88,14 @@ GEM 
     | 
|
| 
       78 
88 
     | 
    
         
             
                thor (1.1.0)
         
     | 
| 
       79 
89 
     | 
    
         
             
                tins (1.29.1)
         
     | 
| 
       80 
90 
     | 
    
         
             
                  sync
         
     | 
| 
      
 91 
     | 
    
         
            +
                tzinfo (2.0.4)
         
     | 
| 
      
 92 
     | 
    
         
            +
                  concurrent-ruby (~> 1.0)
         
     | 
| 
       81 
93 
     | 
    
         
             
                vcr (6.0.0)
         
     | 
| 
       82 
94 
     | 
    
         
             
                webmock (3.14.0)
         
     | 
| 
       83 
95 
     | 
    
         
             
                  addressable (>= 2.8.0)
         
     | 
| 
       84 
96 
     | 
    
         
             
                  crack (>= 0.3.2)
         
     | 
| 
       85 
97 
     | 
    
         
             
                  hashdiff (>= 0.4.0, < 2.0.0)
         
     | 
| 
      
 98 
     | 
    
         
            +
                zeitwerk (2.4.2)
         
     | 
| 
       86 
99 
     | 
    
         | 
| 
       87 
100 
     | 
    
         
             
            PLATFORMS
         
     | 
| 
       88 
101 
     | 
    
         
             
              x86_64-darwin-19
         
     | 
| 
         @@ -93,7 +106,7 @@ DEPENDENCIES 
     | 
|
| 
       93 
106 
     | 
    
         
             
              coveralls
         
     | 
| 
       94 
107 
     | 
    
         
             
              minitest
         
     | 
| 
       95 
108 
     | 
    
         
             
              minitest-reporters
         
     | 
| 
       96 
     | 
    
         
            -
               
     | 
| 
      
 109 
     | 
    
         
            +
              mpesarb!
         
     | 
| 
       97 
110 
     | 
    
         
             
              pry-byebug
         
     | 
| 
       98 
111 
     | 
    
         
             
              rake (>= 12.3)
         
     | 
| 
       99 
112 
     | 
    
         
             
              vcr
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -12,7 +12,12 @@ This Gem provides an interface that developers can use to convert JSON to `OpenS 
     | 
|
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
            Install via `Gemfile`
         
     | 
| 
       14 
14 
     | 
    
         
             
            ```
         
     | 
| 
       15 
     | 
    
         
            -
            gem  
     | 
| 
      
 15 
     | 
    
         
            +
            gem 'mpesarb', '~> 0.3.0'
         
     | 
| 
      
 16 
     | 
    
         
            +
            ```
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            Or
         
     | 
| 
      
 19 
     | 
    
         
            +
            ```
         
     | 
| 
      
 20 
     | 
    
         
            +
            bundle add mpesarb
         
     | 
| 
       16 
21 
     | 
    
         
             
            ```
         
     | 
| 
       17 
22 
     | 
    
         | 
| 
       18 
23 
     | 
    
         
             
            ## Usage
         
     | 
| 
         @@ -20,12 +25,24 @@ gem "mpesa", github: "gathuku/mpesa" 
     | 
|
| 
       20 
25 
     | 
    
         
             
            ### Initialization
         
     | 
| 
       21 
26 
     | 
    
         | 
| 
       22 
27 
     | 
    
         
             
            ```ruby
         
     | 
| 
       23 
     | 
    
         
            -
            client = Mpesa::Client.new(key:  
     | 
| 
      
 28 
     | 
    
         
            +
            client = Mpesa::Client.new(key: 'ZtkRW6ATbVtFpNml5w5SfG26Adfyagn9', secret: 'dosFI1yQ8bvHEVFw', env: 'sandbox')
         
     | 
| 
       24 
29 
     | 
    
         | 
| 
       25 
30 
     | 
    
         
             
            response = client.auth
         
     | 
| 
       26 
31 
     | 
    
         
             
            response.access_token # XiKf3D6UrY0J8S2aeOQ7R7w0BuA5
         
     | 
| 
       27 
32 
     | 
    
         
             
            response.expires_in # 3599
         
     | 
| 
       28 
33 
     | 
    
         
             
            ```
         
     | 
| 
      
 34 
     | 
    
         
            +
            __Parameters__
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            Required
         
     | 
| 
      
 37 
     | 
    
         
            +
            - `key` - API consumer key - Required
         
     | 
| 
      
 38 
     | 
    
         
            +
            - `secret` - API consumer secret  - Required
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            Optional
         
     | 
| 
      
 41 
     | 
    
         
            +
            - `env` - API environment. Default `production`
         
     | 
| 
      
 42 
     | 
    
         
            +
            - `adapter` - Faraday HTTP adapter. Default `:net_http`
         
     | 
| 
      
 43 
     | 
    
         
            +
            - `shortcode` - Mpesa shortcode
         
     | 
| 
      
 44 
     | 
    
         
            +
            - `pass_key` - LPNMO pass Key( used by STK API)
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
       29 
46 
     | 
    
         | 
| 
       30 
47 
     | 
    
         
             
            ### Register Urls
         
     | 
| 
       31 
48 
     | 
    
         | 
| 
         @@ -33,7 +50,8 @@ Register C2B Urls( confirmation and validation url) 
     | 
|
| 
       33 
50 
     | 
    
         
             
            ```ruby
         
     | 
| 
       34 
51 
     | 
    
         
             
             response = client.register(
         
     | 
| 
       35 
52 
     | 
    
         
             
               shortcode: "44445",
         
     | 
| 
       36 
     | 
    
         
            -
               confirmation_url: 'http:// 
     | 
| 
      
 53 
     | 
    
         
            +
               confirmation_url: 'http://example.com/confirm',
         
     | 
| 
      
 54 
     | 
    
         
            +
               validation_url: 'http://example.com/validate'
         
     | 
| 
       37 
55 
     | 
    
         
             
             )
         
     | 
| 
       38 
56 
     | 
    
         
             
             response.OriginatorCoversationID #   "807-15591582-1"
         
     | 
| 
       39 
57 
     | 
    
         
             
             response.ResponseCode # "0"
         
     | 
| 
         @@ -1,7 +1,33 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'active_support/cache'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'active_support/cache/memory_store'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'active_support/notifications'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       1 
5 
     | 
    
         
             
            module Mpesa
         
     | 
| 
       2 
6 
     | 
    
         
             
              class Token < Resource
         
     | 
| 
       3 
7 
     | 
    
         
             
                def token
         
     | 
| 
      
 8 
     | 
    
         
            +
                  if cache.exist?('token')
         
     | 
| 
      
 9 
     | 
    
         
            +
                    expires_at = cache.send(:read_entry, 'token')&.expires_at
         
     | 
| 
      
 10 
     | 
    
         
            +
                    Object.new({
         
     | 
| 
      
 11 
     | 
    
         
            +
                                 "access_token": cache.fetch('token'),
         
     | 
| 
      
 12 
     | 
    
         
            +
                                 "expires_in": expires_at - Time.now.to_f
         
     | 
| 
      
 13 
     | 
    
         
            +
                               })
         
     | 
| 
      
 14 
     | 
    
         
            +
                  else
         
     | 
| 
      
 15 
     | 
    
         
            +
                    cache_token
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def cache_token
         
     | 
| 
      
 20 
     | 
    
         
            +
                  res = call
         
     | 
| 
      
 21 
     | 
    
         
            +
                  cache.write('token', res.access_token, expires_in: res.expires_in)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  res
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                def call
         
     | 
| 
       4 
26 
     | 
    
         
             
                  Object.new get_request(url: 'oauth/v1/generate?grant_type=client_credentials', basic_auth: true).body
         
     | 
| 
       5 
27 
     | 
    
         
             
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                def cache
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @cache ||= ActiveSupport::Cache::MemoryStore.new
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
       6 
32 
     | 
    
         
             
              end
         
     | 
| 
       7 
33 
     | 
    
         
             
            end
         
     | 
    
        data/lib/mpesa/version.rb
    CHANGED
    
    
    
        data/mpesa.gemspec
    CHANGED
    
    | 
         @@ -30,6 +30,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       30 
30 
     | 
    
         
             
              spec.add_development_dependency 'bundler', '>= 2.1.4'
         
     | 
| 
       31 
31 
     | 
    
         
             
              spec.add_development_dependency 'rake', '>= 12.3'
         
     | 
| 
       32 
32 
     | 
    
         
             
              # dependancies
         
     | 
| 
      
 33 
     | 
    
         
            +
              spec.add_runtime_dependency 'activesupport', '>= 5.0.0'
         
     | 
| 
       33 
34 
     | 
    
         
             
              spec.add_runtime_dependency 'faraday', '>= 1.1'
         
     | 
| 
       34 
35 
     | 
    
         
             
              spec.add_runtime_dependency 'faraday_middleware', '~> 1.1'
         
     | 
| 
       35 
36 
     | 
    
         
             
              spec.add_runtime_dependency 'openssl', '>= 2.1'
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: mpesarb
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Moses Gathuku
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2021-09- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-09-15 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -38,6 +38,20 @@ dependencies: 
     | 
|
| 
       38 
38 
     | 
    
         
             
                - - ">="
         
     | 
| 
       39 
39 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       40 
40 
     | 
    
         
             
                    version: '12.3'
         
     | 
| 
      
 41 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 42 
     | 
    
         
            +
              name: activesupport
         
     | 
| 
      
 43 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 44 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 45 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 46 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 47 
     | 
    
         
            +
                    version: 5.0.0
         
     | 
| 
      
 48 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 49 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 50 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 51 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 52 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 53 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 54 
     | 
    
         
            +
                    version: 5.0.0
         
     | 
| 
       41 
55 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       42 
56 
     | 
    
         
             
              name: faraday
         
     | 
| 
       43 
57 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     |