cenit-api 0.0.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 +7 -0
 - data/CODE_OF_CONDUCT.md +74 -0
 - data/Gemfile +8 -0
 - data/LICENSE.txt +21 -0
 - data/README.md +177 -0
 - data/bin/console +7 -0
 - data/bin/setup +4 -0
 - data/cenit-api.gemspec +28 -0
 - data/lib/cenit/api.rb +67 -0
 - data/lib/cenit/api/data_type.rb +71 -0
 - data/lib/cenit/api/error.rb +7 -0
 - data/lib/cenit/api/hash.rb +10 -0
 - data/lib/cenit/api/http_creatable.rb +17 -0
 - data/lib/cenit/api/http_data_requester.rb +24 -0
 - data/lib/cenit/api/http_destroyable.rb +17 -0
 - data/lib/cenit/api/http_query.rb +23 -0
 - data/lib/cenit/api/http_readable.rb +13 -0
 - data/lib/cenit/api/http_requester.rb +30 -0
 - data/lib/cenit/api/http_updateable.rb +17 -0
 - data/lib/cenit/api/namespace.rb +27 -0
 - data/lib/cenit/api/record.rb +20 -0
 - data/lib/cenit/api/url_slug.rb +19 -0
 - data/lib/cenit/api/version.rb +6 -0
 - metadata +163 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: d12b08319d2e4b54bd39e053b576064698accdfe
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 36f26e8c8938136caa4a55c9372d32e47b55c070
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 31c271f85514b0486dbabffad6c7384979607c8599691ee085c270ba94a28534c83e0d707043947b5fcf8923f9e3b52c4b14b49a4b595098ca5cc73853a4b3be
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 097d6977fa7a0027d1b37d6c90041076514aad0181be598d82beb276bdc6b2fc41b9ab83773b12b3360785adb033183306ab9a612468ce8fafa9199efcd5bb99
         
     | 
    
        data/CODE_OF_CONDUCT.md
    ADDED
    
    | 
         @@ -0,0 +1,74 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Contributor Covenant Code of Conduct
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            ## Our Pledge
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            In the interest of fostering an open and welcoming environment, we as
         
     | 
| 
      
 6 
     | 
    
         
            +
            contributors and maintainers pledge to making participation in our project and
         
     | 
| 
      
 7 
     | 
    
         
            +
            our community a harassment-free experience for everyone, regardless of age, body
         
     | 
| 
      
 8 
     | 
    
         
            +
            size, disability, ethnicity, gender identity and expression, level of experience,
         
     | 
| 
      
 9 
     | 
    
         
            +
            nationality, personal appearance, race, religion, or sexual identity and
         
     | 
| 
      
 10 
     | 
    
         
            +
            orientation.
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ## Our Standards
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            Examples of behavior that contributes to creating a positive environment
         
     | 
| 
      
 15 
     | 
    
         
            +
            include:
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            * Using welcoming and inclusive language
         
     | 
| 
      
 18 
     | 
    
         
            +
            * Being respectful of differing viewpoints and experiences
         
     | 
| 
      
 19 
     | 
    
         
            +
            * Gracefully accepting constructive criticism
         
     | 
| 
      
 20 
     | 
    
         
            +
            * Focusing on what is best for the community
         
     | 
| 
      
 21 
     | 
    
         
            +
            * Showing empathy towards other community members
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            Examples of unacceptable behavior by participants include:
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            * The use of sexualized language or imagery and unwelcome sexual attention or
         
     | 
| 
      
 26 
     | 
    
         
            +
            advances
         
     | 
| 
      
 27 
     | 
    
         
            +
            * Trolling, insulting/derogatory comments, and personal or political attacks
         
     | 
| 
      
 28 
     | 
    
         
            +
            * Public or private harassment
         
     | 
| 
      
 29 
     | 
    
         
            +
            * Publishing others' private information, such as a physical or electronic
         
     | 
| 
      
 30 
     | 
    
         
            +
              address, without explicit permission
         
     | 
| 
      
 31 
     | 
    
         
            +
            * Other conduct which could reasonably be considered inappropriate in a
         
     | 
| 
      
 32 
     | 
    
         
            +
              professional setting
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            ## Our Responsibilities
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            Project maintainers are responsible for clarifying the standards of acceptable
         
     | 
| 
      
 37 
     | 
    
         
            +
            behavior and are expected to take appropriate and fair corrective action in
         
     | 
| 
      
 38 
     | 
    
         
            +
            response to any instances of unacceptable behavior.
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            Project maintainers have the right and responsibility to remove, edit, or
         
     | 
| 
      
 41 
     | 
    
         
            +
            reject comments, commits, code, wiki edits, issues, and other contributions
         
     | 
| 
      
 42 
     | 
    
         
            +
            that are not aligned to this Code of Conduct, or to ban temporarily or
         
     | 
| 
      
 43 
     | 
    
         
            +
            permanently any contributor for other behaviors that they deem inappropriate,
         
     | 
| 
      
 44 
     | 
    
         
            +
            threatening, offensive, or harmful.
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            ## Scope
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            This Code of Conduct applies both within project spaces and in public spaces
         
     | 
| 
      
 49 
     | 
    
         
            +
            when an individual is representing the project or its community. Examples of
         
     | 
| 
      
 50 
     | 
    
         
            +
            representing a project or community include using an official project e-mail
         
     | 
| 
      
 51 
     | 
    
         
            +
            address, posting via an official social media account, or acting as an appointed
         
     | 
| 
      
 52 
     | 
    
         
            +
            representative at an online or offline event. Representation of a project may be
         
     | 
| 
      
 53 
     | 
    
         
            +
            further defined and clarified by project maintainers.
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            ## Enforcement
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            Instances of abusive, harassing, or otherwise unacceptable behavior may be
         
     | 
| 
      
 58 
     | 
    
         
            +
            reported by contacting the project team at macarci@gmail.com. All
         
     | 
| 
      
 59 
     | 
    
         
            +
            complaints will be reviewed and investigated and will result in a response that
         
     | 
| 
      
 60 
     | 
    
         
            +
            is deemed necessary and appropriate to the circumstances. The project team is
         
     | 
| 
      
 61 
     | 
    
         
            +
            obligated to maintain confidentiality with regard to the reporter of an incident.
         
     | 
| 
      
 62 
     | 
    
         
            +
            Further details of specific enforcement policies may be posted separately.
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            Project maintainers who do not follow or enforce the Code of Conduct in good
         
     | 
| 
      
 65 
     | 
    
         
            +
            faith may face temporary or permanent repercussions as determined by other
         
     | 
| 
      
 66 
     | 
    
         
            +
            members of the project's leadership.
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            ## Attribution
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
         
     | 
| 
      
 71 
     | 
    
         
            +
            available at [http://contributor-covenant.org/version/1/4][version]
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            [homepage]: http://contributor-covenant.org
         
     | 
| 
      
 74 
     | 
    
         
            +
            [version]: http://contributor-covenant.org/version/1/4/
         
     | 
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            The MIT License (MIT)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Copyright (c) 2017 Maikel Arcia
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         
     | 
| 
      
 6 
     | 
    
         
            +
            of this software and associated documentation files (the "Software"), to deal
         
     | 
| 
      
 7 
     | 
    
         
            +
            in the Software without restriction, including without limitation the rights
         
     | 
| 
      
 8 
     | 
    
         
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         
     | 
| 
      
 9 
     | 
    
         
            +
            copies of the Software, and to permit persons to whom the Software is
         
     | 
| 
      
 10 
     | 
    
         
            +
            furnished to do so, subject to the following conditions:
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be included in
         
     | 
| 
      
 13 
     | 
    
         
            +
            all copies or substantial portions of the Software.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         
     | 
| 
      
 16 
     | 
    
         
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         
     | 
| 
      
 17 
     | 
    
         
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         
     | 
| 
      
 18 
     | 
    
         
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         
     | 
| 
      
 19 
     | 
    
         
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         
     | 
| 
      
 20 
     | 
    
         
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         
     | 
| 
      
 21 
     | 
    
         
            +
            THE SOFTWARE.
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,177 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Cenit API
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Provides a Ruby client to interact with a Cenit API using a DSL to route your resources and to build
         
     | 
| 
      
 4 
     | 
    
         
            +
            queries and options for result rendering.
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            Add this line to your application's Gemfile:
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 11 
     | 
    
         
            +
            gem 'cenit-api'
         
     | 
| 
      
 12 
     | 
    
         
            +
            ```
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                $ bundle
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            Or install it yourself as:
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                $ gem install cenit-api
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            Querying Shared Collections from https://cenit.io
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 27 
     | 
    
         
            +
            require 'cenit/api'
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            Cenit::API.v2.setup.cross_shared_collection.get # { "total_pages": 1, "current_page": 1, "count": 282, "cross_shared_collections": [ { "id": ...
         
     | 
| 
      
 30 
     | 
    
         
            +
            ```
         
     | 
| 
      
 31 
     | 
    
         
            +
            Or you can use a constant syntax for the API version
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 34 
     | 
    
         
            +
            Cenit::API::V2.setup.cross_shared_collection.count # 282
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            ```
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            ## CRUD operations
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            To create objects or access non shared data you must configure your Cenit credentials:
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 43 
     | 
    
         
            +
            Cenit.access_token 'XXXXXXXXXX'
         
     | 
| 
      
 44 
     | 
    
         
            +
            Cenit.access_key   'KKKKKKKKKK'
         
     | 
| 
      
 45 
     | 
    
         
            +
            ```
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
             If you want to use your own instance of Cenit then configure your host URL by:
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 50 
     | 
    
         
            +
            Cenit.host 'my-cenit-host-url'
         
     | 
| 
      
 51 
     | 
    
         
            +
            ```
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            Lets create a JSON data type and some records
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 56 
     | 
    
         
            +
            api = Cenit::API::V2
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            api.setup.json_data_type.create namespace: 'Test',
         
     | 
| 
      
 59 
     | 
    
         
            +
                                            name: 'Object',
         
     | 
| 
      
 60 
     | 
    
         
            +
                                            schema: {
         
     | 
| 
      
 61 
     | 
    
         
            +
                                                type: 'object',
         
     | 
| 
      
 62 
     | 
    
         
            +
                                                properties: {
         
     | 
| 
      
 63 
     | 
    
         
            +
                                                    id: { type: 'integer' },
         
     | 
| 
      
 64 
     | 
    
         
            +
                                                    label: { type: 'string' },
         
     | 
| 
      
 65 
     | 
    
         
            +
                                                    checked: { type: 'boolean' }
         
     | 
| 
      
 66 
     | 
    
         
            +
                                                },
         
     | 
| 
      
 67 
     | 
    
         
            +
                                                required: ['label']
         
     | 
| 
      
 68 
     | 
    
         
            +
                                            }
         
     | 
| 
      
 69 
     | 
    
         
            +
                                            # {"success": {"json_data_type": {"id": "58fa2faece50767158000006", "namespace": "Test", "name": "Object",...
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
            api.test.object.create(id: 0, label: 'Label') # {"success": {"object": {"id": 0, "label": "Label"}}}
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            api.test.object.create((1..10).collect { |i| { id: i, label: "Label #{i}", checked: i.odd? } }) # {"success": {"object": {"id": 10, "label": "Label 10", "checked": false}}}
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            api.test.object.count # 11
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            # READ
         
     | 
| 
      
 78 
     | 
    
         
            +
            api.test.object.get     # {"total_pages": 1, "current_page": 1, "count": 11, "objects": [{"id": 0, "label": "Label"}, {"id": 1, "label": "Label 1",...
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            api.test.object(0).get  # {"id": 0, "label": "Label"}
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
            # UPDATE
         
     | 
| 
      
 83 
     | 
    
         
            +
            api.test.object(0).update(label: 'X') # {"id": 0, "label": "X"}
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            #DELETE
         
     | 
| 
      
 86 
     | 
    
         
            +
            api.test.object(10).delete  # {"status": "ok"}
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
            api.test.object(10).get     # {"status": "item not found"},
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
            api.test.object(10).get.code    # 404
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
            api.test.object.count       # 10
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
            ```
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
            ## Query DSL
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
            `cenit-api` use the query DSL defined by `origin` including the Cenit API parameters:
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 101 
     | 
    
         
            +
            api.test.object.where(checked: false).collect { |obj| obj['id'] }               # [2, 4, 6, 8]
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
            api.test.object.where(checked: true).collect { |obj| obj['label'] }             # ["Label 1", "Label 3", "Label 5", "Label 7", "Label 9"]
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
            api.test.object.where(:checked.exists => false).collect { |obj| obj['label'] }  # ["X"]
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
            api.test.object.where(:id.gt => 4).first                                        # {"id": 5, "label": "Label 5", "checked": true}
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
            api.test.object.where(:id.gt => 4).descending(:label).ignore(:checked).first    # {"id": 9, "label": "Label 9"}
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
            api.test.object.limit(2).page(3).get                                            # {"total_pages": 5, "current_page": 3, "count": 10, "objects": [{"id": 4,...
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
            ```
         
     | 
| 
      
 114 
     | 
    
         
            +
            ## Push API
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
            Lets first create another test data type using the Push API
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 119 
     | 
    
         
            +
            api.setup.push  json_data_type: {
         
     | 
| 
      
 120 
     | 
    
         
            +
                                 namespace: 'Test',
         
     | 
| 
      
 121 
     | 
    
         
            +
                                 name: 'Record',
         
     | 
| 
      
 122 
     | 
    
         
            +
                                 schema: {
         
     | 
| 
      
 123 
     | 
    
         
            +
                                     type: 'object',
         
     | 
| 
      
 124 
     | 
    
         
            +
                                     properties: {
         
     | 
| 
      
 125 
     | 
    
         
            +
                                         name: { type: 'string' },
         
     | 
| 
      
 126 
     | 
    
         
            +
                                         number: { type: 'integer' }
         
     | 
| 
      
 127 
     | 
    
         
            +
                                     }
         
     | 
| 
      
 128 
     | 
    
         
            +
                                 }
         
     | 
| 
      
 129 
     | 
    
         
            +
                            }
         
     | 
| 
      
 130 
     | 
    
         
            +
                            # {"success": {"json_data_types": [{"id": "58fa4efcce50760627000012", "namespace": "Test", "name": "Record",...
         
     | 
| 
      
 131 
     | 
    
         
            +
            ```
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
            And then make a data type simultaneous push to the `test` namespace
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 136 
     | 
    
         
            +
            api.test.push   objects: [
         
     | 
| 
      
 137 
     | 
    
         
            +
                                { id: 10, label: "Label TEN" },
         
     | 
| 
      
 138 
     | 
    
         
            +
                                { id: 11, label: "Label ELEVEN" }
         
     | 
| 
      
 139 
     | 
    
         
            +
                            ],
         
     | 
| 
      
 140 
     | 
    
         
            +
                            records: [
         
     | 
| 
      
 141 
     | 
    
         
            +
                                { name: 'Record 1', number: 1 },
         
     | 
| 
      
 142 
     | 
    
         
            +
                                { name: 'Record 2', number: 2 }
         
     | 
| 
      
 143 
     | 
    
         
            +
                            ]
         
     | 
| 
      
 144 
     | 
    
         
            +
            ```
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
            The result should look like
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
            ```json
         
     | 
| 
      
 149 
     | 
    
         
            +
            {
         
     | 
| 
      
 150 
     | 
    
         
            +
                "success": {
         
     | 
| 
      
 151 
     | 
    
         
            +
                    "objects": [
         
     | 
| 
      
 152 
     | 
    
         
            +
                        {"id": 10, "label": "Label TEN", "checked": false},
         
     | 
| 
      
 153 
     | 
    
         
            +
                        {"id": 11, "label": "Label ELEVEN"}
         
     | 
| 
      
 154 
     | 
    
         
            +
                    ],
         
     | 
| 
      
 155 
     | 
    
         
            +
                    "records": [
         
     | 
| 
      
 156 
     | 
    
         
            +
                        {"id": "58fa517fce50760627000017", "name": "Record 1", "number": 1},
         
     | 
| 
      
 157 
     | 
    
         
            +
                        {"id": "58fa5180ce50760627000018", "name": "Record 2", "number": 2}
         
     | 
| 
      
 158 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 159 
     | 
    
         
            +
                }
         
     | 
| 
      
 160 
     | 
    
         
            +
            }
         
     | 
| 
      
 161 
     | 
    
         
            +
            ```
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
            ## Development
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
            After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
            ## Contributing
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/cenit-io/cenit-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
            ## License
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
            The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
    
        data/bin/console
    ADDED
    
    
    
        data/bin/setup
    ADDED
    
    
    
        data/cenit-api.gemspec
    ADDED
    
    | 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            lib = File.expand_path('../lib', __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'cenit/api/version'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Gem::Specification.new do |spec|
         
     | 
| 
      
 6 
     | 
    
         
            +
              spec.name          = 'cenit-api'
         
     | 
| 
      
 7 
     | 
    
         
            +
              spec.version       = Cenit::API::VERSION
         
     | 
| 
      
 8 
     | 
    
         
            +
              spec.authors       = ['Maikel Arcia']
         
     | 
| 
      
 9 
     | 
    
         
            +
              spec.email         = ['macarci@gmail.com']
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              spec.summary       = %q{A Ruby client to interact with a Cenit API.}
         
     | 
| 
      
 12 
     | 
    
         
            +
              spec.description   = %q{Provides a Ruby client to interact with a Cenit API using a DSL to route your resources and to build queries and options for result rendering.}
         
     | 
| 
      
 13 
     | 
    
         
            +
              spec.homepage      = 'https://cenit.io'
         
     | 
| 
      
 14 
     | 
    
         
            +
              spec.license       = 'MIT'
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         
     | 
| 
      
 17 
     | 
    
         
            +
              spec.bindir        = 'exe'
         
     | 
| 
      
 18 
     | 
    
         
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         
     | 
| 
      
 19 
     | 
    
         
            +
              spec.require_paths = ['lib']
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              spec.add_development_dependency 'bundler', '~> 1.14'
         
     | 
| 
      
 22 
     | 
    
         
            +
              spec.add_development_dependency 'rake', '~> 10.0'
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              spec.add_runtime_dependency 'cenit-config', '~> 0.0.1'
         
     | 
| 
      
 25 
     | 
    
         
            +
              spec.add_runtime_dependency 'hashie', '~> 3.4', '>= 3.4.3'
         
     | 
| 
      
 26 
     | 
    
         
            +
              spec.add_runtime_dependency 'httparty', '~> 0.13.7'
         
     | 
| 
      
 27 
     | 
    
         
            +
              spec.add_runtime_dependency 'origin', '~> 2.1', '>= 2.1.1'
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/cenit/api.rb
    ADDED
    
    | 
         @@ -0,0 +1,67 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'cenit/api/version'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'cenit/api/hash'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'httparty'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'origin'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            require 'cenit/api/url_slug'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'cenit/api/http_query'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'cenit/api/http_requester'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'cenit/api/http_data_requester'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'cenit/api/http_creatable'
         
     | 
| 
      
 12 
     | 
    
         
            +
            require 'cenit/api/http_updateable'
         
     | 
| 
      
 13 
     | 
    
         
            +
            require 'cenit/api/http_readable'
         
     | 
| 
      
 14 
     | 
    
         
            +
            require 'cenit/api/http_destroyable'
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            require 'cenit/api/record'
         
     | 
| 
      
 17 
     | 
    
         
            +
            require 'cenit/api/data_type'
         
     | 
| 
      
 18 
     | 
    
         
            +
            require 'cenit/api/namespace'
         
     | 
| 
      
 19 
     | 
    
         
            +
            require 'cenit/api/error'
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            require 'cenit/config'
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              module API
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                class Version
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  ALL = %w(v1 v2).collect(&:to_sym).freeze
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  DEPRECATED = %w(v1).collect(&:to_sym).freeze
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  include Cenit::API::UrlSlug
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  def method_missing(symbol, *args)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    (args.length == 0 && Namespace.new(symbol, self)) || super
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  def method_missing(symbol, *args)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    (args.length == 0 && version(symbol)) || super
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  def const_missing(symbol)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    symbol = symbol.to_s.downcase.to_sym
         
     | 
| 
      
 48 
     | 
    
         
            +
                    version(symbol) || super
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  def version(name)
         
     | 
| 
      
 52 
     | 
    
         
            +
                    name = name.to_s.to_sym
         
     | 
| 
      
 53 
     | 
    
         
            +
                    if Version::ALL.include?(name)
         
     | 
| 
      
 54 
     | 
    
         
            +
                      if Version::DEPRECATED.include?(name)
         
     | 
| 
      
 55 
     | 
    
         
            +
                        fail Error, "Deprecated version: #{name}"
         
     | 
| 
      
 56 
     | 
    
         
            +
                      else
         
     | 
| 
      
 57 
     | 
    
         
            +
                        Version.new(name, self)
         
     | 
| 
      
 58 
     | 
    
         
            +
                      end
         
     | 
| 
      
 59 
     | 
    
         
            +
                    end
         
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                  def url
         
     | 
| 
      
 63 
     | 
    
         
            +
                    "#{Cenit.host}/api"
         
     | 
| 
      
 64 
     | 
    
         
            +
                  end
         
     | 
| 
      
 65 
     | 
    
         
            +
                end
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
      
 67 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,71 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                class DataType
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  include UrlSlug
         
     | 
| 
      
 6 
     | 
    
         
            +
                  include HttpReadable
         
     | 
| 
      
 7 
     | 
    
         
            +
                  include HttpCreatable
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  include Origin::Queryable
         
     | 
| 
      
 10 
     | 
    
         
            +
                  include Enumerable
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def initialize(slug, parent = nil)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @slug = slug
         
     | 
| 
      
 14 
     | 
    
         
            +
                    @parent = parent
         
     | 
| 
      
 15 
     | 
    
         
            +
                    super()
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  def default_headers
         
     | 
| 
      
 19 
     | 
    
         
            +
                    Hash[super].deep_merge('X-Query-Selector' => process_hash(selector).to_json,
         
     | 
| 
      
 20 
     | 
    
         
            +
                                           'X-Query-Options' => options.to_json)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  def count
         
     | 
| 
      
 24 
     | 
    
         
            +
                    if (response = get).code == 200
         
     | 
| 
      
 25 
     | 
    
         
            +
                      response['count']
         
     | 
| 
      
 26 
     | 
    
         
            +
                    else
         
     | 
| 
      
 27 
     | 
    
         
            +
                      nil
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  def each
         
     | 
| 
      
 32 
     | 
    
         
            +
                    if block_given?
         
     | 
| 
      
 33 
     | 
    
         
            +
                      page = 1
         
     | 
| 
      
 34 
     | 
    
         
            +
                      while page
         
     | 
| 
      
 35 
     | 
    
         
            +
                        if (response = get(query: { page: page, limit: 0 })).code == 200
         
     | 
| 
      
 36 
     | 
    
         
            +
                          (response.values.detect { |v| v.is_a?(Array) } || []).each do |item|
         
     | 
| 
      
 37 
     | 
    
         
            +
                            yield(item)
         
     | 
| 
      
 38 
     | 
    
         
            +
                          end
         
     | 
| 
      
 39 
     | 
    
         
            +
                          page =
         
     | 
| 
      
 40 
     | 
    
         
            +
                            if response['total_pages'] > page
         
     | 
| 
      
 41 
     | 
    
         
            +
                              page + 1
         
     | 
| 
      
 42 
     | 
    
         
            +
                            else
         
     | 
| 
      
 43 
     | 
    
         
            +
                              nil
         
     | 
| 
      
 44 
     | 
    
         
            +
                            end
         
     | 
| 
      
 45 
     | 
    
         
            +
                        else
         
     | 
| 
      
 46 
     | 
    
         
            +
                          fail Error, "Unsuccessful response code: #{response.code}"
         
     | 
| 
      
 47 
     | 
    
         
            +
                        end
         
     | 
| 
      
 48 
     | 
    
         
            +
                      end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    end
         
     | 
| 
      
 50 
     | 
    
         
            +
                  end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                  def process_hash(hash)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    h = {}
         
     | 
| 
      
 54 
     | 
    
         
            +
                    hash.each do |key, value|
         
     | 
| 
      
 55 
     | 
    
         
            +
                      h[key] =
         
     | 
| 
      
 56 
     | 
    
         
            +
                        case value
         
     | 
| 
      
 57 
     | 
    
         
            +
                        when Regexp
         
     | 
| 
      
 58 
     | 
    
         
            +
                          { '$regex': value.to_s }
         
     | 
| 
      
 59 
     | 
    
         
            +
                        when Hash
         
     | 
| 
      
 60 
     | 
    
         
            +
                          process_hash(value)
         
     | 
| 
      
 61 
     | 
    
         
            +
                        else
         
     | 
| 
      
 62 
     | 
    
         
            +
                          value
         
     | 
| 
      
 63 
     | 
    
         
            +
                        end
         
     | 
| 
      
 64 
     | 
    
         
            +
                    end
         
     | 
| 
      
 65 
     | 
    
         
            +
                    h
         
     | 
| 
      
 66 
     | 
    
         
            +
                  end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                  protected :process_hash
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
      
 71 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                module HttpCreatable
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  include HttpDataRequester
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def post(data, options = {}, &block)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    do_data_request(:post, data, options, &block)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  def create(data, options = {}, &block)
         
     | 
| 
      
 12 
     | 
    
         
            +
                    post(data, options, &block)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                module HttpDataRequester
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  include HttpRequester
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def do_request(method, options = {})
         
     | 
| 
      
 8 
     | 
    
         
            +
                    options[:body] =
         
     | 
| 
      
 9 
     | 
    
         
            +
                      case (body = options[:body])
         
     | 
| 
      
 10 
     | 
    
         
            +
                      when Array, ::Hash
         
     | 
| 
      
 11 
     | 
    
         
            +
                        body.to_json
         
     | 
| 
      
 12 
     | 
    
         
            +
                      else
         
     | 
| 
      
 13 
     | 
    
         
            +
                        body.to_s
         
     | 
| 
      
 14 
     | 
    
         
            +
                      end
         
     | 
| 
      
 15 
     | 
    
         
            +
                    super
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  def do_data_request(method, data, options = {}, &block)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    options[:body] = data
         
     | 
| 
      
 20 
     | 
    
         
            +
                    do_request(method, options, &block)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                module HttpDestroyable
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  include HttpRequester
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def delete(options = {}, &block)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    do_request(:delete, options, &block)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  def destroy(options = {}, &block)
         
     | 
| 
      
 12 
     | 
    
         
            +
                    delete(options, &block)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                module HttpQuery
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  def query
         
     | 
| 
      
 6 
     | 
    
         
            +
                    @query ||= {}
         
     | 
| 
      
 7 
     | 
    
         
            +
                  end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  def method_missing(symbol, *args)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    case args.length
         
     | 
| 
      
 11 
     | 
    
         
            +
                    when 0
         
     | 
| 
      
 12 
     | 
    
         
            +
                      super
         
     | 
| 
      
 13 
     | 
    
         
            +
                    when 1
         
     | 
| 
      
 14 
     | 
    
         
            +
                      query[symbol] = args[0]
         
     | 
| 
      
 15 
     | 
    
         
            +
                      self
         
     | 
| 
      
 16 
     | 
    
         
            +
                    else
         
     | 
| 
      
 17 
     | 
    
         
            +
                      query[symbol] = args.collect(&:to_s).flatten.join(',')
         
     | 
| 
      
 18 
     | 
    
         
            +
                      self
         
     | 
| 
      
 19 
     | 
    
         
            +
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                module HttpRequester
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  include HttpQuery
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def do_request(method, options = {})
         
     | 
| 
      
 8 
     | 
    
         
            +
                    options = Hash[{ headers: default_headers, query: query }].deep_merge(options)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    response = HTTParty.send(method, options[:url] || url, options)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    if block_given?
         
     | 
| 
      
 11 
     | 
    
         
            +
                      yield response
         
     | 
| 
      
 12 
     | 
    
         
            +
                    else
         
     | 
| 
      
 13 
     | 
    
         
            +
                      response
         
     | 
| 
      
 14 
     | 
    
         
            +
                    end
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  def default_headers
         
     | 
| 
      
 18 
     | 
    
         
            +
                    headers = { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 19 
     | 
    
         
            +
                    if (token = Cenit.access_token) && (key = Cenit.access_key)
         
     | 
| 
      
 20 
     | 
    
         
            +
                      headers['X-User-Access-Key'] = key
         
     | 
| 
      
 21 
     | 
    
         
            +
                      headers['X-User-Access-Token'] = token
         
     | 
| 
      
 22 
     | 
    
         
            +
                    end
         
     | 
| 
      
 23 
     | 
    
         
            +
                    headers
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  protected :do_request, :default_headers
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                module HttpUpdateable
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  include HttpDataRequester
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def post(data, options = {}, &block)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    do_data_request(:post, data, options, &block)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  def update(data, options = {}, &block)
         
     | 
| 
      
 12 
     | 
    
         
            +
                    post(data, options, &block)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                class Namespace
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  include UrlSlug
         
     | 
| 
      
 6 
     | 
    
         
            +
                  include HttpDataRequester
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  def push(data, options = {})
         
     | 
| 
      
 9 
     | 
    
         
            +
                    options[:url] = "#{url}/push"
         
     | 
| 
      
 10 
     | 
    
         
            +
                    do_data_request(:post, data, options)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def method_missing(symbol, *args)
         
     | 
| 
      
 14 
     | 
    
         
            +
                    if args.length < 2
         
     | 
| 
      
 15 
     | 
    
         
            +
                      dt = DataType.new(symbol, self)
         
     | 
| 
      
 16 
     | 
    
         
            +
                      if args.length == 1
         
     | 
| 
      
 17 
     | 
    
         
            +
                        Record.new(args[0], dt)
         
     | 
| 
      
 18 
     | 
    
         
            +
                      else
         
     | 
| 
      
 19 
     | 
    
         
            +
                        dt
         
     | 
| 
      
 20 
     | 
    
         
            +
                      end
         
     | 
| 
      
 21 
     | 
    
         
            +
                    else
         
     | 
| 
      
 22 
     | 
    
         
            +
                      super
         
     | 
| 
      
 23 
     | 
    
         
            +
                    end
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Cenit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                module UrlSlug
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  attr_reader :parent, :slug
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def initialize(slug, parent = nil)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @slug = slug
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @parent = parent
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def url
         
     | 
| 
      
 13 
     | 
    
         
            +
                    url = parent ? parent.url : ''
         
     | 
| 
      
 14 
     | 
    
         
            +
                    "#{url}/#{slug}"
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,163 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: cenit-api
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Maikel Arcia
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: exe
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-04-21 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 13 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 14 
     | 
    
         
            +
              name: bundler
         
     | 
| 
      
 15 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    version: '1.14'
         
     | 
| 
      
 20 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 21 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 22 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 23 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    version: '1.14'
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: rake
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: '10.0'
         
     | 
| 
      
 34 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 35 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                    version: '10.0'
         
     | 
| 
      
 41 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 42 
     | 
    
         
            +
              name: cenit-config
         
     | 
| 
      
 43 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 44 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 45 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 46 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 47 
     | 
    
         
            +
                    version: 0.0.1
         
     | 
| 
      
 48 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 49 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 50 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 51 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 52 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 53 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 54 
     | 
    
         
            +
                    version: 0.0.1
         
     | 
| 
      
 55 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 56 
     | 
    
         
            +
              name: hashie
         
     | 
| 
      
 57 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 58 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 59 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 60 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 61 
     | 
    
         
            +
                    version: '3.4'
         
     | 
| 
      
 62 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 63 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 64 
     | 
    
         
            +
                    version: 3.4.3
         
     | 
| 
      
 65 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 66 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 67 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 68 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 69 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 70 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 71 
     | 
    
         
            +
                    version: '3.4'
         
     | 
| 
      
 72 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 73 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 74 
     | 
    
         
            +
                    version: 3.4.3
         
     | 
| 
      
 75 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 76 
     | 
    
         
            +
              name: httparty
         
     | 
| 
      
 77 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 78 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 79 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 80 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 81 
     | 
    
         
            +
                    version: 0.13.7
         
     | 
| 
      
 82 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 83 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 84 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 85 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 86 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 87 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 88 
     | 
    
         
            +
                    version: 0.13.7
         
     | 
| 
      
 89 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 90 
     | 
    
         
            +
              name: origin
         
     | 
| 
      
 91 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 92 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 93 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 94 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 95 
     | 
    
         
            +
                    version: '2.1'
         
     | 
| 
      
 96 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 97 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 98 
     | 
    
         
            +
                    version: 2.1.1
         
     | 
| 
      
 99 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 100 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 101 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 102 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 103 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 104 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 105 
     | 
    
         
            +
                    version: '2.1'
         
     | 
| 
      
 106 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 107 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 108 
     | 
    
         
            +
                    version: 2.1.1
         
     | 
| 
      
 109 
     | 
    
         
            +
            description: Provides a Ruby client to interact with a Cenit API using a DSL to route
         
     | 
| 
      
 110 
     | 
    
         
            +
              your resources and to build queries and options for result rendering.
         
     | 
| 
      
 111 
     | 
    
         
            +
            email:
         
     | 
| 
      
 112 
     | 
    
         
            +
            - macarci@gmail.com
         
     | 
| 
      
 113 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 114 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 115 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 116 
     | 
    
         
            +
            files:
         
     | 
| 
      
 117 
     | 
    
         
            +
            - CODE_OF_CONDUCT.md
         
     | 
| 
      
 118 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 119 
     | 
    
         
            +
            - LICENSE.txt
         
     | 
| 
      
 120 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 121 
     | 
    
         
            +
            - bin/console
         
     | 
| 
      
 122 
     | 
    
         
            +
            - bin/setup
         
     | 
| 
      
 123 
     | 
    
         
            +
            - cenit-api.gemspec
         
     | 
| 
      
 124 
     | 
    
         
            +
            - lib/cenit/api.rb
         
     | 
| 
      
 125 
     | 
    
         
            +
            - lib/cenit/api/data_type.rb
         
     | 
| 
      
 126 
     | 
    
         
            +
            - lib/cenit/api/error.rb
         
     | 
| 
      
 127 
     | 
    
         
            +
            - lib/cenit/api/hash.rb
         
     | 
| 
      
 128 
     | 
    
         
            +
            - lib/cenit/api/http_creatable.rb
         
     | 
| 
      
 129 
     | 
    
         
            +
            - lib/cenit/api/http_data_requester.rb
         
     | 
| 
      
 130 
     | 
    
         
            +
            - lib/cenit/api/http_destroyable.rb
         
     | 
| 
      
 131 
     | 
    
         
            +
            - lib/cenit/api/http_query.rb
         
     | 
| 
      
 132 
     | 
    
         
            +
            - lib/cenit/api/http_readable.rb
         
     | 
| 
      
 133 
     | 
    
         
            +
            - lib/cenit/api/http_requester.rb
         
     | 
| 
      
 134 
     | 
    
         
            +
            - lib/cenit/api/http_updateable.rb
         
     | 
| 
      
 135 
     | 
    
         
            +
            - lib/cenit/api/namespace.rb
         
     | 
| 
      
 136 
     | 
    
         
            +
            - lib/cenit/api/record.rb
         
     | 
| 
      
 137 
     | 
    
         
            +
            - lib/cenit/api/url_slug.rb
         
     | 
| 
      
 138 
     | 
    
         
            +
            - lib/cenit/api/version.rb
         
     | 
| 
      
 139 
     | 
    
         
            +
            homepage: https://cenit.io
         
     | 
| 
      
 140 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 141 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 142 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 143 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 144 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 145 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 146 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 147 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 148 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 149 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 150 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 151 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 152 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 153 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 154 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 155 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 156 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 157 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 158 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 159 
     | 
    
         
            +
            rubygems_version: 2.4.8
         
     | 
| 
      
 160 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 161 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 162 
     | 
    
         
            +
            summary: A Ruby client to interact with a Cenit API.
         
     | 
| 
      
 163 
     | 
    
         
            +
            test_files: []
         
     |