squarespace_api 0.0.6 → 0.0.7
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 +11 -7
- data/README.md +36 -16
- data/lib/squarespace_api/paginated_fetch.rb +4 -4
- data/lib/squarespace_api/resource_group.rb +4 -0
- data/lib/squarespace_api/resource_group_actions.rb +5 -4
- data/lib/squarespace_api/version.rb +1 -1
- data/spec/squarespace_api/resource_group_actions_spec.rb +27 -0
- data/spec/squarespace_api_spec.rb +1 -1
- data/squarespace_api.gemspec +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7605a851dda2e468747c0133620edb3763d8961c935ca15b005e3a4b406fefa7
         | 
| 4 | 
            +
              data.tar.gz: 1fb57f3e5cd318a7f3d0167927ee58521d3b76ecdd24ee5ea25daa408d2bb8e0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 334a4961dc1130524e539ae650ac7cb7697fadad88fa1509aa08b0b765e9d31683690b49ab7d5b9a03728e4b1832e5b46acdfaa66d1d9fc9129baaf77e578f5d
         | 
| 7 | 
            +
              data.tar.gz: 3205784829d70dd252340dd7fa620066a380703a84f73be2f036b303d616b3b59886ce301bb8791ffc45afae6f101de4075672ff089e54a1c8da16573b7873d4
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                squarespace_api (0.0. | 
| 4 | 
            +
                squarespace_api (0.0.7)
         | 
| 5 5 | 
             
                  faraday
         | 
| 6 6 | 
             
                  faraday_middleware
         | 
| 7 7 | 
             
                  json
         | 
| @@ -15,29 +15,33 @@ GEM | |
| 15 15 | 
             
                crack (0.4.5)
         | 
| 16 16 | 
             
                  rexml
         | 
| 17 17 | 
             
                diff-lcs (1.4.4)
         | 
| 18 | 
            -
                faraday (1. | 
| 18 | 
            +
                faraday (1.10.0)
         | 
| 19 19 | 
             
                  faraday-em_http (~> 1.0)
         | 
| 20 20 | 
             
                  faraday-em_synchrony (~> 1.0)
         | 
| 21 21 | 
             
                  faraday-excon (~> 1.1)
         | 
| 22 | 
            -
                  faraday-httpclient (~> 1.0 | 
| 22 | 
            +
                  faraday-httpclient (~> 1.0)
         | 
| 23 | 
            +
                  faraday-multipart (~> 1.0)
         | 
| 23 24 | 
             
                  faraday-net_http (~> 1.0)
         | 
| 24 | 
            -
                  faraday-net_http_persistent (~> 1. | 
| 25 | 
            +
                  faraday-net_http_persistent (~> 1.0)
         | 
| 25 26 | 
             
                  faraday-patron (~> 1.0)
         | 
| 26 27 | 
             
                  faraday-rack (~> 1.0)
         | 
| 27 | 
            -
                   | 
| 28 | 
            +
                  faraday-retry (~> 1.0)
         | 
| 28 29 | 
             
                  ruby2_keywords (>= 0.0.4)
         | 
| 29 30 | 
             
                faraday-em_http (1.0.0)
         | 
| 30 31 | 
             
                faraday-em_synchrony (1.0.0)
         | 
| 31 32 | 
             
                faraday-excon (1.1.0)
         | 
| 32 33 | 
             
                faraday-httpclient (1.0.1)
         | 
| 34 | 
            +
                faraday-multipart (1.0.3)
         | 
| 35 | 
            +
                  multipart-post (>= 1.2, < 3)
         | 
| 33 36 | 
             
                faraday-net_http (1.0.1)
         | 
| 34 37 | 
             
                faraday-net_http_persistent (1.2.0)
         | 
| 35 38 | 
             
                faraday-patron (1.0.0)
         | 
| 36 39 | 
             
                faraday-rack (1.0.0)
         | 
| 37 | 
            -
                 | 
| 40 | 
            +
                faraday-retry (1.0.3)
         | 
| 41 | 
            +
                faraday_middleware (1.2.0)
         | 
| 38 42 | 
             
                  faraday (~> 1.0)
         | 
| 39 43 | 
             
                hashdiff (1.0.1)
         | 
| 40 | 
            -
                json (2. | 
| 44 | 
            +
                json (2.6.1)
         | 
| 41 45 | 
             
                method_source (1.0.0)
         | 
| 42 46 | 
             
                multipart-post (2.1.1)
         | 
| 43 47 | 
             
                pry (0.14.1)
         | 
    
        data/README.md
    CHANGED
    
    | @@ -20,7 +20,7 @@ gem 'squarespace_api' | |
| 20 20 |  | 
| 21 21 |  | 
| 22 22 |  | 
| 23 | 
            -
            ##  | 
| 23 | 
            +
            ## Quick Example
         | 
| 24 24 |  | 
| 25 25 | 
             
            - Thread Safety Usage
         | 
| 26 26 |  | 
| @@ -90,7 +90,7 @@ client.products.delete(id) | |
| 90 90 | 
             
            - ProductImages
         | 
| 91 91 |  | 
| 92 92 | 
             
            ```ruby
         | 
| 93 | 
            -
            # Noted that Path parameters should be passed in  | 
| 93 | 
            +
            # Noted that Path parameters should be passed in params.
         | 
| 94 94 | 
             
            client.product_images.upload(file_path, { product_id: product_id })
         | 
| 95 95 | 
             
            client.product_images.status(id, { product_id: product_id })
         | 
| 96 96 | 
             
            client.product_images.order(id, { product_id: product_id, afterImageId: 'otherImageId' })
         | 
| @@ -100,7 +100,7 @@ client.product_images.update(id, { product_id: product_id, altText: 'my_picture' | |
| 100 100 | 
             
            - ProductVariants
         | 
| 101 101 |  | 
| 102 102 | 
             
            ```ruby
         | 
| 103 | 
            -
            # Noted that Path parameters should be passed in  | 
| 103 | 
            +
            # Noted that Path parameters should be passed in params.
         | 
| 104 104 | 
             
            client.product_variants.create({ product_id: product_id })
         | 
| 105 105 | 
             
            client.product_variants.update(id, { sku: 'P1234', product_id: product_id })
         | 
| 106 106 | 
             
            ```
         | 
| @@ -122,6 +122,7 @@ client.inventory_adjustments.create(params) | |
| 122 122 | 
             
            ```
         | 
| 123 123 |  | 
| 124 124 | 
             
            - Profiles
         | 
| 125 | 
            +
             | 
| 125 126 | 
             
            ```ruby
         | 
| 126 127 | 
             
            client.profiles.all
         | 
| 127 128 | 
             
            client.profiles.find(id)
         | 
| @@ -129,6 +130,7 @@ client.profiles.create(params) | |
| 129 130 | 
             
            ```
         | 
| 130 131 |  | 
| 131 132 | 
             
            - StorePages
         | 
| 133 | 
            +
             | 
| 132 134 | 
             
            ```ruby
         | 
| 133 135 | 
             
            client.store_pages.all
         | 
| 134 136 | 
             
            ```
         | 
| @@ -153,7 +155,8 @@ client.webhook_subscriptions.send_test_notification(id, params) | |
| 153 155 | 
             
            client.webhook_subscriptions.rotate_secret(id)
         | 
| 154 156 | 
             
            ```
         | 
| 155 157 |  | 
| 156 | 
            -
             | 
| 158 | 
            +
             | 
| 159 | 
            +
            ## Single Resource
         | 
| 157 160 |  | 
| 158 161 | 
             
            - Website
         | 
| 159 162 |  | 
| @@ -161,9 +164,11 @@ client.webhook_subscriptions.rotate_secret(id) | |
| 161 164 | 
             
            client.website
         | 
| 162 165 | 
             
            ```
         | 
| 163 166 |  | 
| 164 | 
            -
            ## | 
| 167 | 
            +
            ## Oauth App
         | 
| 168 | 
            +
             | 
| 169 | 
            +
            ### Configuration
         | 
| 165 170 |  | 
| 166 | 
            -
             | 
| 171 | 
            +
            configure your oauth cerdentials in ENV:
         | 
| 167 172 |  | 
| 168 173 | 
             
            ```ruby
         | 
| 169 174 | 
             
            # Auto load ENV
         | 
| @@ -171,30 +176,44 @@ SQUARESPACE_CLIENT_ID = 'your client id' | |
| 171 176 | 
             
            SQUARESPACE_CLIENT_SECRET = 'your client secret'
         | 
| 172 177 | 
             
            ```
         | 
| 173 178 |  | 
| 179 | 
            +
            Or configure in your initializer:
         | 
| 180 | 
            +
             | 
| 181 | 
            +
            ```ruby
         | 
| 182 | 
            +
            SquarespaceApi.configure do |c|
         | 
| 183 | 
            +
              c.client_id = 'your client id'
         | 
| 184 | 
            +
              c.client_secret = 'your client secret'
         | 
| 185 | 
            +
            end
         | 
| 186 | 
            +
            ```
         | 
| 187 | 
            +
             | 
| 188 | 
            +
            If you have multiple apps, consider thread safe usage:
         | 
| 189 | 
            +
             | 
| 190 | 
            +
            ```ruby
         | 
| 191 | 
            +
            client = SquarespaceApi::Client.new(
         | 
| 192 | 
            +
              SquarespaceApi::Config.new(
         | 
| 193 | 
            +
                client_id: 'your client id',
         | 
| 194 | 
            +
                client_secret: 'your client secret'
         | 
| 195 | 
            +
              )
         | 
| 196 | 
            +
            )
         | 
| 197 | 
            +
            ```
         | 
| 198 | 
            +
             | 
| 199 | 
            +
            ### Oauth Actions
         | 
| 200 | 
            +
             | 
| 174 201 | 
             
            - Construct Oauth Url
         | 
| 175 202 |  | 
| 176 203 | 
             
            ```ruby
         | 
| 177 | 
            -
             | 
| 204 | 
            +
            SquarespaceApi::Client.new.build_oauth_authorize_url(
         | 
| 178 205 | 
             
              redirect_url: 'https://api.test.com/squarespace',
         | 
| 179 206 | 
             
              scope: 'website.orders,website.orders.read',
         | 
| 180 207 | 
             
              state: '1234',
         | 
| 181 208 | 
             
              access_type: "offline"
         | 
| 182 209 | 
             
            )
         | 
| 210 | 
            +
             | 
| 183 211 | 
             
            => 'https://login.squarespace.com/api/1/login/oauth/provider/authorize?client_id=&redirect_url=https://api.test.com/squarespace&scope=website.orders,website.orders.read&state=1234&access_type=offline'
         | 
| 184 212 | 
             
            ```
         | 
| 185 213 |  | 
| 186 214 | 
             
            - Request Access Token
         | 
| 187 215 |  | 
| 188 216 | 
             
            ```ruby
         | 
| 189 | 
            -
            client = SquarespaceApi::Client.new(
         | 
| 190 | 
            -
              SquarespaceApi::Config.new(
         | 
| 191 | 
            -
                # your can specifize application credentials if you have multiple apps
         | 
| 192 | 
            -
                # otherwise it'll auto load env
         | 
| 193 | 
            -
                client_id: 'your client id',
         | 
| 194 | 
            -
                client_secret: 'your client secret'
         | 
| 195 | 
            -
              )
         | 
| 196 | 
            -
            )
         | 
| 197 | 
            -
             | 
| 198 217 | 
             
            # request access token
         | 
| 199 218 | 
             
            client.tokens.create(
         | 
| 200 219 | 
             
              code: 'code sent from Squaerspace',
         | 
| @@ -203,6 +222,7 @@ client.tokens.create( | |
| 203 222 | 
             
            ```
         | 
| 204 223 |  | 
| 205 224 | 
             
            - Request Refresh Token
         | 
| 225 | 
            +
             | 
| 206 226 | 
             
            ```ruby
         | 
| 207 227 | 
             
            client.tokens.create(
         | 
| 208 228 | 
             
              refresh_token: 'some_refresh_token',
         | 
| @@ -2,11 +2,11 @@ module SquarespaceApi | |
| 2 2 | 
             
              module PaginatedFetch
         | 
| 3 3 | 
             
                def self.build(params = {}, &_block)
         | 
| 4 4 | 
             
                  loop do
         | 
| 5 | 
            -
                     | 
| 5 | 
            +
                    pagination = yield(params)
         | 
| 6 6 |  | 
| 7 | 
            -
                    has_next_page =  | 
| 8 | 
            -
                    break  | 
| 9 | 
            -
                    params = { cursor:   | 
| 7 | 
            +
                    has_next_page = !!pagination&.dig('hasNextPage')
         | 
| 8 | 
            +
                    break if not has_next_page
         | 
| 9 | 
            +
                    params = { cursor:  pagination['nextPageCursor'] }
         | 
| 10 10 | 
             
                  end
         | 
| 11 11 | 
             
                end
         | 
| 12 12 | 
             
              end
         | 
| @@ -6,13 +6,14 @@ module SquarespaceApi | |
| 6 6 | 
             
                module All
         | 
| 7 7 | 
             
                  def all(params = {}, &_block)
         | 
| 8 8 | 
             
                    PaginatedFetch.build(params) do |paginated_params|
         | 
| 9 | 
            -
                       | 
| 10 | 
            -
                        connection
         | 
| 9 | 
            +
                      query_result = connection
         | 
| 11 10 | 
             
                        .get(UriComponentBuidler.construct(resources_path, paginated_params), params: paginated_params)
         | 
| 12 | 
            -
                      )
         | 
| 11 | 
            +
                      response = parse_collection(query_result)
         | 
| 12 | 
            +
                      pagination = parse_pagination(query_result)
         | 
| 13 | 
            +
             | 
| 13 14 | 
             
                      return response unless block_given?
         | 
| 14 15 | 
             
                      yield(response)
         | 
| 15 | 
            -
                       | 
| 16 | 
            +
                      pagination
         | 
| 16 17 | 
             
                    end
         | 
| 17 18 | 
             
                  end
         | 
| 18 19 |  | 
| @@ -22,6 +22,33 @@ describe SquarespaceApi::ResourceGroupActions do | |
| 22 22 |  | 
| 23 23 | 
             
                it { expect(resource.all(status: 'pending')).to eq([]) }
         | 
| 24 24 | 
             
                it { expect(resource.where(status: 'pending')).to eq([]) }
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                context "when pagination exists" do
         | 
| 27 | 
            +
                  before do
         | 
| 28 | 
            +
                    stub_request(:get, "https://api.squarespace.com/1.0/commerce/dummy?status=pending")
         | 
| 29 | 
            +
                      .to_return(status: 200, body: {
         | 
| 30 | 
            +
                        'dummy' => [{ 'id' => 1 }],
         | 
| 31 | 
            +
                        'pagination' => { "hasNextPage" => true, 'nextPageCursor' => "cursor"
         | 
| 32 | 
            +
                        }
         | 
| 33 | 
            +
                      }.to_json)
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    stub_request(:get, "https://api.squarespace.com/1.0/commerce/dummy?cursor=cursor")
         | 
| 36 | 
            +
                      .to_return(status: 200, body: {
         | 
| 37 | 
            +
                        'dummy' => [{ 'id' => 2 }],
         | 
| 38 | 
            +
                        'pagination' => { "hasNextPage" => false }
         | 
| 39 | 
            +
                      }.to_json)
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  it "should return all orders" do
         | 
| 43 | 
            +
                    orders = []
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                    resource.all(status: 'pending') do |new_orders|
         | 
| 46 | 
            +
                      orders += new_orders
         | 
| 47 | 
            +
                    end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    expect(orders).to eq([{ 'id' => 1 }, { 'id' => 2 }])
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                end
         | 
| 25 52 | 
             
              end
         | 
| 26 53 |  | 
| 27 54 | 
             
              describe '#find' do
         | 
    
        data/squarespace_api.gemspec
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            Gem::Specification.new do |spec|
         | 
| 2 2 | 
             
              spec.name        = "squarespace_api"
         | 
| 3 | 
            -
              spec.version     = "0.0. | 
| 3 | 
            +
              spec.version     = "0.0.7"
         | 
| 4 4 | 
             
              spec.summary     = "Ruby gem interacting with the Squarespace API."
         | 
| 5 5 | 
             
              spec.description = "Ruby gem interacting with the Squarespace API."
         | 
| 6 6 | 
             
              spec.authors     = ["cdragon"]
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: squarespace_api
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - cdragon
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2022-03-31 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rspec
         | 
| @@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 162 162 | 
             
                - !ruby/object:Gem::Version
         | 
| 163 163 | 
             
                  version: '0'
         | 
| 164 164 | 
             
            requirements: []
         | 
| 165 | 
            -
            rubygems_version: 3.0. | 
| 165 | 
            +
            rubygems_version: 3.0.9
         | 
| 166 166 | 
             
            signing_key:
         | 
| 167 167 | 
             
            specification_version: 4
         | 
| 168 168 | 
             
            summary: Ruby gem interacting with the Squarespace API.
         |