pocus 0.6.1 → 1.1.0
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/README.md +22 -8
- data/lib/pocus/account.rb +2 -0
- data/lib/pocus/association.rb +4 -0
- data/lib/pocus/client_folder.rb +0 -1
- data/lib/pocus/identity.rb +1 -1
- data/lib/pocus/resource.rb +5 -4
- data/lib/pocus/session.rb +13 -11
- metadata +4 -50
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 50a4404a6f892888678d3d4fdd038133696beaece4d7cbb6e7e92dffd8b00b8e
         | 
| 4 | 
            +
              data.tar.gz: 2418eef7353f39b5b7ff913993277ba1369707c7e64ae03b5baef40a2c8551c7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c993ee6385f43f1fc06d7253bfc4c790c713c9fabba38199ee225ec25db188141cd7ccc61fff4b6ab090a6d17f7d753be154cc65e95ba5505e9cc5dbcc6e34ab
         | 
| 7 | 
            +
              data.tar.gz: ec1ebf2100cf5390c412eac26ea5586068e24b4cc2c80a968a86b7700e7610ab49cf2531c9f10ba28370552a04735dc93e81d4c2276b56465d82d11f76f2e24e
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,8 +1,7 @@ | |
| 1 1 | 
             
            # Pocus
         | 
| 2 2 |  | 
| 3 3 | 
             
            [](http://badge.fury.io/rb/pocus)
         | 
| 4 | 
            -
            [](https://travis-ci.org/varyonic/pocus)
         | 
| 4 | 
            +
            [![Github Actions  ][actions_badge]][actions]
         | 
| 6 5 |  | 
| 7 6 | 
             
            Unofficial Ruby API client for [iContact API](https://www.icontact.com/developerportal) (f.k.a. Vocus), inspired by Active Resource.
         | 
| 8 7 |  | 
| @@ -18,21 +17,33 @@ And then execute: | |
| 18 17 |  | 
| 19 18 | 
             
                $ bundle
         | 
| 20 19 |  | 
| 20 | 
            +
            ## Requirements
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            iContact account, AppID and credentials, see the [iContact API Getting Started Guide](https://www.icontact.com/developerportal/documentation/start-building).
         | 
| 23 | 
            +
             | 
| 21 24 | 
             
            ## Usage
         | 
| 22 25 |  | 
| 23 | 
            -
             | 
| 26 | 
            +
            Configure a connection and connect to the account:
         | 
| 24 27 |  | 
| 28 | 
            +
            ```ruby
         | 
| 29 | 
            +
                credentials = { host: 'app.icontact.com', app_id: a, username: u, password: p }
         | 
| 30 | 
            +
                session = Pocus::Session.new(credentials)
         | 
| 31 | 
            +
                session.logger = Rails.logger
         | 
| 32 | 
            +
            	account = Pocus::Account.new(session: session, account_id: account_id)
         | 
| 25 33 | 
             
            ```
         | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 34 | 
            +
             | 
| 35 | 
            +
            Navigate and update entities:
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ```ruby
         | 
| 29 38 | 
             
            	folder = acount.clientfolders.find(folder_id)
         | 
| 30 39 | 
             
            	folder.contacts.create(contacts_data)
         | 
| 31 40 | 
             
            ```
         | 
| 32 41 |  | 
| 42 | 
            +
            See the specs for sample code.
         | 
| 43 | 
            +
             | 
| 33 44 | 
             
            ## Tests
         | 
| 34 45 |  | 
| 35 | 
            -
            To run the tests you will need your own iContact account with a test folder.  Set the following environment variables:
         | 
| 46 | 
            +
            To run the tests you will need your own iContact account with a test folder (name: 'My First List').  Set the following environment variables:
         | 
| 36 47 |  | 
| 37 48 | 
             
            ```
         | 
| 38 49 | 
             
            POCUS_APP_ID=0b34...b478c
         | 
| @@ -59,4 +70,7 @@ The gem is available as open source under the terms of the [MIT License](https:/ | |
| 59 70 |  | 
| 60 71 | 
             
            Read the [LICENSE](LICENSE.md) for details.
         | 
| 61 72 |  | 
| 62 | 
            -
            Copyright (c) 2016- | 
| 73 | 
            +
            Copyright (c) 2016-2025 [Varyonic](https://www.varyonic.com).
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            [actions_badge]: https://github.com/varyonic/pocus/workflows/ci/badge.svg
         | 
| 76 | 
            +
            [actions]: https://github.com/varyonic/pocus/actions
         | 
    
        data/lib/pocus/account.rb
    CHANGED
    
    
    
        data/lib/pocus/association.rb
    CHANGED
    
    
    
        data/lib/pocus/client_folder.rb
    CHANGED
    
    
    
        data/lib/pocus/identity.rb
    CHANGED
    
    
    
        data/lib/pocus/resource.rb
    CHANGED
    
    | @@ -5,7 +5,7 @@ module Pocus | |
| 5 5 |  | 
| 6 6 | 
             
                def initialize(resources, errors, warnings)
         | 
| 7 7 | 
             
                  @errors = (errors || [])
         | 
| 8 | 
            -
                  @warnings = (warnings || [])
         | 
| 8 | 
            +
                  @warnings = (warnings || []).reject { |w| w =~ /Your account is past due/ }
         | 
| 9 9 | 
             
                  super resources
         | 
| 10 10 | 
             
                end
         | 
| 11 11 | 
             
              end
         | 
| @@ -106,7 +106,8 @@ module Pocus | |
| 106 106 | 
             
                def post_multiple(request_path, klass, fields_multiple)
         | 
| 107 107 | 
             
                  data = fields_multiple.map { |fields| camelize_fields(fields) }
         | 
| 108 108 | 
             
                  response = session.send_request('POST', path + request_path, data)
         | 
| 109 | 
            -
                   | 
| 109 | 
            +
                  data = response.fetch(klass.tag_multiple) || []
         | 
| 110 | 
            +
                  resources = data.map { |fields| klass.new(fields.merge(parent: self)) }
         | 
| 110 111 | 
             
                  ResponseArray.new(resources, response['errors'], response['warnings'])
         | 
| 111 112 | 
             
                end
         | 
| 112 113 |  | 
| @@ -119,7 +120,7 @@ module Pocus | |
| 119 120 | 
             
                end
         | 
| 120 121 |  | 
| 121 122 | 
             
                def session
         | 
| 122 | 
            -
                   | 
| 123 | 
            +
                  parent.session
         | 
| 123 124 | 
             
                end
         | 
| 124 125 |  | 
| 125 126 | 
             
                def marshal_dump
         | 
| @@ -165,7 +166,7 @@ module Pocus | |
| 165 166 | 
             
                end
         | 
| 166 167 |  | 
| 167 168 | 
             
                def assign_errors(response)
         | 
| 168 | 
            -
                  assign_attributes(errors: response['errors'] || [], warnings: response['warnings'] || [])
         | 
| 169 | 
            +
                  assign_attributes(errors: response['errors'] || [], warnings: (response['warnings'] || []).reject { |w| w =~ /Your account is past due/ })
         | 
| 169 170 | 
             
                end
         | 
| 170 171 |  | 
| 171 172 | 
             
                def underscore(camel_cased_word)
         | 
    
        data/lib/pocus/session.rb
    CHANGED
    
    | @@ -16,11 +16,12 @@ module Pocus | |
| 16 16 |  | 
| 17 17 | 
             
              # Sends authenticated JSON requests to remote service using HTTPS.
         | 
| 18 18 | 
             
              class Session
         | 
| 19 | 
            -
                 | 
| 19 | 
            +
                attr_reader :base_url
         | 
| 20 20 | 
             
                attr_reader :credentials
         | 
| 21 21 | 
             
                attr_accessor :logger
         | 
| 22 22 |  | 
| 23 | 
            -
                def initialize( | 
| 23 | 
            +
                def initialize(host: 'api.invoc.us', app_id:, username:, password:, logger: Logger.new('/dev/null'))
         | 
| 24 | 
            +
                  @base_url = "https://#{host}/icp".freeze
         | 
| 24 25 | 
             
                  @credentials = {
         | 
| 25 26 | 
             
                    'API-AppId'    => app_id,
         | 
| 26 27 | 
             
                    'API-Username' => username,
         | 
| @@ -29,18 +30,15 @@ module Pocus | |
| 29 30 | 
             
                  @logger = logger
         | 
| 30 31 | 
             
                end
         | 
| 31 32 |  | 
| 32 | 
            -
                 | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
                def self.instance
         | 
| 37 | 
            -
                  @instance ||= new(@config)
         | 
| 33 | 
            +
                # 'Pro' is legacy as moniker dropped.
         | 
| 34 | 
            +
                def pro?
         | 
| 35 | 
            +
                  base_url =~ /invoc.us/
         | 
| 38 36 | 
             
                end
         | 
| 39 37 |  | 
| 40 38 | 
             
                # Accepts hash of fields to send.
         | 
| 41 39 | 
             
                # Returns parsed response body, always a hash.
         | 
| 42 40 | 
             
                def send_request(method, path, fields = {})
         | 
| 43 | 
            -
                  response = send_logged_request(URI( | 
| 41 | 
            +
                  response = send_logged_request(URI(base_url + path), method, request_data(fields))
         | 
| 44 42 | 
             
                  fail UnexpectedHttpResponse, response unless response.is_a? Net::HTTPSuccess
         | 
| 45 43 | 
             
                  JSON.parse(response.body)
         | 
| 46 44 | 
             
                end
         | 
| @@ -69,13 +67,17 @@ module Pocus | |
| 69 67 | 
             
                end
         | 
| 70 68 |  | 
| 71 69 | 
             
                def log_request_response(uri, method, data)
         | 
| 72 | 
            -
                  logger.info  | 
| 70 | 
            +
                  logger.info  "[#{self.class.name}] request = #{method} #{uri}#{data ? '?' + data : ''}"
         | 
| 73 71 | 
             
                  response = nil
         | 
| 74 72 | 
             
                  tms = Benchmark.measure do
         | 
| 75 73 | 
             
                    response = yield uri, method, data
         | 
| 76 74 | 
             
                  end
         | 
| 77 | 
            -
                  logger.info | 
| 75 | 
            +
                  logger.info  "[#{self.class.name}] response (#{ms(tms)}ms): #{response.inspect} #{response.body}"
         | 
| 78 76 | 
             
                  response
         | 
| 79 77 | 
             
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                def ms(tms)
         | 
| 80 | 
            +
                  (tms.real*1000).round(3)
         | 
| 81 | 
            +
                end
         | 
| 80 82 | 
             
              end
         | 
| 81 83 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,59 +1,16 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: pocus
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 1.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Piers Chambers
         | 
| 8 | 
            -
            autorequire: 
         | 
| 9 8 | 
             
            bindir: bin
         | 
| 10 9 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 10 | 
            +
            date: 1980-01-02 00:00:00.000000000 Z
         | 
| 12 11 | 
             
            dependencies:
         | 
| 13 12 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 13 | 
             
              name: rake
         | 
| 15 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            -
                requirements:
         | 
| 17 | 
            -
                - - "~>"
         | 
| 18 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: '11.0'
         | 
| 20 | 
            -
              type: :development
         | 
| 21 | 
            -
              prerelease: false
         | 
| 22 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            -
                requirements:
         | 
| 24 | 
            -
                - - "~>"
         | 
| 25 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: '11.0'
         | 
| 27 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            -
              name: pry
         | 
| 29 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            -
                requirements:
         | 
| 31 | 
            -
                - - ">="
         | 
| 32 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: '0'
         | 
| 34 | 
            -
              type: :development
         | 
| 35 | 
            -
              prerelease: false
         | 
| 36 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            -
                requirements:
         | 
| 38 | 
            -
                - - ">="
         | 
| 39 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: '0'
         | 
| 41 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            -
              name: pry-byebug
         | 
| 43 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            -
                requirements:
         | 
| 45 | 
            -
                - - ">="
         | 
| 46 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: '0'
         | 
| 48 | 
            -
              type: :development
         | 
| 49 | 
            -
              prerelease: false
         | 
| 50 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            -
                requirements:
         | 
| 52 | 
            -
                - - ">="
         | 
| 53 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: '0'
         | 
| 55 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            -
              name: pry-state
         | 
| 57 14 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 15 | 
             
                requirements:
         | 
| 59 16 | 
             
                - - ">="
         | 
| @@ -86,8 +43,8 @@ email: | |
| 86 43 | 
             
            executables: []
         | 
| 87 44 | 
             
            extensions: []
         | 
| 88 45 | 
             
            extra_rdoc_files:
         | 
| 89 | 
            -
            - README.md
         | 
| 90 46 | 
             
            - LICENSE.md
         | 
| 47 | 
            +
            - README.md
         | 
| 91 48 | 
             
            files:
         | 
| 92 49 | 
             
            - LICENSE.md
         | 
| 93 50 | 
             
            - README.md
         | 
| @@ -112,7 +69,6 @@ homepage: https://github.com/varyonic/pocus | |
| 112 69 | 
             
            licenses:
         | 
| 113 70 | 
             
            - MIT
         | 
| 114 71 | 
             
            metadata: {}
         | 
| 115 | 
            -
            post_install_message: 
         | 
| 116 72 | 
             
            rdoc_options: []
         | 
| 117 73 | 
             
            require_paths:
         | 
| 118 74 | 
             
            - lib
         | 
| @@ -127,9 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 127 83 | 
             
                - !ruby/object:Gem::Version
         | 
| 128 84 | 
             
                  version: '0'
         | 
| 129 85 | 
             
            requirements: []
         | 
| 130 | 
            -
             | 
| 131 | 
            -
            rubygems_version: 2.7.7
         | 
| 132 | 
            -
            signing_key: 
         | 
| 86 | 
            +
            rubygems_version: 3.6.7
         | 
| 133 87 | 
             
            specification_version: 4
         | 
| 134 88 | 
             
            summary: Unofficial Ruby client for iContact API
         | 
| 135 89 | 
             
            test_files: []
         |