usergrid_iron 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +72 -33
- data/lib/usergrid/core/application.rb +3 -1
- data/lib/usergrid/core/collection.rb +3 -3
- data/lib/usergrid/core/entity.rb +1 -1
- data/lib/usergrid/core/management.rb +9 -4
- data/lib/usergrid/core/organization.rb +4 -2
- data/lib/usergrid/core/resource.rb +1 -1
- data/lib/usergrid/version.rb +1 -1
- data/lib/{usergrid.rb → usergrid_iron.rb} +0 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/usergrid/core/application_spec.rb +1 -1
- data/spec/usergrid/core/collection_spec.rb +2 -3
- data/spec/usergrid/extensions/hash_spec.rb +1 -1
- metadata +5 -5
    
        data/README.md
    CHANGED
    
    | @@ -26,65 +26,104 @@ Or install it yourself as: | |
| 26 26 | 
             
            Docs: http://apigee.com/docs/usergrid/
         | 
| 27 27 | 
             
            Open source: https://github.com/apigee/usergrid-stack
         | 
| 28 28 |  | 
| 29 | 
            -
            2. Getting started with the Usergrid_iron SDK is simple! Let's  | 
| 30 | 
            -
             | 
| 29 | 
            +
            2. Getting started with the Usergrid_iron SDK is simple! Let's start with the basics.
         | 
| 30 | 
            +
            I'll assume you've already set up an organization, application, and user - just fill in your
         | 
| 31 | 
            +
            own values in the code below.
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            <pre>
         | 
| 34 | 
            +
            require 'usergrid_iron'
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            # fill in your values here!
         | 
| 37 | 
            +
            usergrid_api = 'http://localhost:8080'
         | 
| 38 | 
            +
            organization = ''
         | 
| 39 | 
            +
            application = ''
         | 
| 40 | 
            +
            username = ''
         | 
| 41 | 
            +
            password = ''
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            application = Usergrid::Application.new "#{usergrid_api}/#{organization}/#{application}"
         | 
| 44 | 
            +
            application.login username, password
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            # create and store a dog in the 'dogs' collection on the server
         | 
| 47 | 
            +
            response = application.create_entity 'dogs', { breed: 'Black Mouth Cur', name: 'Old Yeller' }
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            # let's get the dog from the response and grab its persistent id
         | 
| 50 | 
            +
            dog = response.entity
         | 
| 51 | 
            +
            uuid = dog.uuid
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            # let's retrieve a dog from the server by UUID
         | 
| 54 | 
            +
            same_dog = application['dogs'][uuid].entity
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            # is it our dog? well, he knows his name!
         | 
| 57 | 
            +
            puts "My dog's name is: #{same_dog.name}"
         | 
| 58 | 
            +
            </pre>
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            That was really easy. So let's try something slightly more complex.
         | 
| 61 | 
            +
            Let's say we've registered for an organization, but we don't have an application yet (or
         | 
| 62 | 
            +
            want to create a new one to work on). No worries, just fill in your organization and
         | 
| 63 | 
            +
            superuser credentials below, and follow along! (Better yet: If you used the Usergrid launcher
         | 
| 64 | 
            +
            and let it initialize your database, you shouldn't need to do anything!)
         | 
| 31 65 |  | 
| 32 66 | 
             
            <pre>
         | 
| 33 67 | 
             
              require 'usergrid_iron'
         | 
| 34 68 |  | 
| 35 | 
            -
               | 
| 36 | 
            -
               | 
| 69 | 
            +
              usergrid_api = 'http://localhost:8080'
         | 
| 70 | 
            +
              org_name = 'test-organization'
         | 
| 71 | 
            +
              username = 'test'
         | 
| 72 | 
            +
              password = 'test'
         | 
| 73 | 
            +
              app_name = 'dog_sitter'
         | 
| 74 | 
            +
             | 
| 75 | 
            +
              ## first, let's get that setup out of the way ##
         | 
| 37 76 |  | 
| 38 77 | 
             
              # get a management context & login the superuser
         | 
| 39 | 
            -
              management = usergrid_api | 
| 40 | 
            -
              management.login  | 
| 78 | 
            +
              management = Usergrid::Management.new usergrid_api
         | 
| 79 | 
            +
              management.login username, password
         | 
| 41 80 |  | 
| 42 81 | 
             
              # get the organization context & create a new application
         | 
| 43 | 
            -
               | 
| 44 | 
            -
               | 
| 45 | 
            -
             | 
| 82 | 
            +
              organization = management.organization org_name
         | 
| 83 | 
            +
              new_application = organization.create_application app_name
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              # create an user for our application
         | 
| 86 | 
            +
              new_application.create_user 'username', 'name', 'email@test.com', 'password'
         | 
| 87 | 
            +
             | 
| 46 88 |  | 
| 47 | 
            -
               | 
| 48 | 
            -
              application.create_user 'app_username', 'app_name', 'app_email@test.com', 'password'
         | 
| 89 | 
            +
              ## now we can play with the puppies! ##
         | 
| 49 90 |  | 
| 50 | 
            -
              #  | 
| 51 | 
            -
              application =  | 
| 52 | 
            -
              application.login ' | 
| 91 | 
            +
              # login to our new application as our new user
         | 
| 92 | 
            +
              application = Usergrid::Application.new "#{usergrid_api}/#{org_name}/#{app_name}"
         | 
| 93 | 
            +
              application.login 'username', 'password'
         | 
| 53 94 |  | 
| 54 | 
            -
              #  | 
| 55 | 
            -
              application.create_entity | 
| 95 | 
            +
              # we can start with our dog again
         | 
| 96 | 
            +
              application.create_entity 'dogs', { breed: 'Black Mouth Cur', name: 'Old Yeller' }
         | 
| 56 97 |  | 
| 57 | 
            -
              # create several more dogs
         | 
| 98 | 
            +
              # but this time let's create several more dogs at once
         | 
| 58 99 | 
             
              application.create_entities 'dogs', [{ breed: 'Catalan sheepdog', name: 'Einstein' },
         | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 100 | 
            +
                  { breed: 'Cocker Spaniel', name: 'Lady' },
         | 
| 101 | 
            +
                  { breed: 'Mixed', name: 'Benji' }]
         | 
| 61 102 |  | 
| 62 | 
            -
              #  | 
| 63 | 
            -
              dogs = application['dogs']. | 
| 103 | 
            +
              # retrieve all the dogs (well, the first 'page' anyway) and tell them hi!
         | 
| 104 | 
            +
              dogs = application['dogs'].collection
         | 
| 64 105 | 
             
              dogs.each do |dog|                          # works just like an array
         | 
| 65 | 
            -
                 | 
| 106 | 
            +
                puts "Hello, #{dog.name}!"                # entities automatically have attributes
         | 
| 66 107 | 
             
              end
         | 
| 67 108 |  | 
| 68 | 
            -
              #  | 
| 69 | 
            -
              dogs.query | 
| 70 | 
            -
              benji = dogs.first
         | 
| 109 | 
            +
              # "Benji, come!"
         | 
| 110 | 
            +
              benji = dogs.query("select * where name = 'Benji'").entity  # shortcut: entity will return the first in the collection
         | 
| 71 111 |  | 
| 72 112 | 
             
              # modify Benji's attributes & save
         | 
| 73 | 
            -
              benji. | 
| 113 | 
            +
              benji.location = 'home'                     # use attribute access
         | 
| 74 114 | 
             
              benji['breed'] = 'American Cocker Spaniel'  # or access it like a Hash
         | 
| 75 115 | 
             
              benji.save
         | 
| 76 116 |  | 
| 77 | 
            -
              #  | 
| 78 | 
            -
               | 
| 79 | 
            -
              if  | 
| 80 | 
            -
                puts "Benji's  | 
| 81 | 
            -
              else
         | 
| 82 | 
            -
                raise 'Benji is a lost puppy!'
         | 
| 117 | 
            +
              # query for the dogs that are home (should just be Benji)
         | 
| 118 | 
            +
              dogs = application['dogs'].query("select * where location = 'home'").collection
         | 
| 119 | 
            +
              if dogs.size == 1 && dogs.first == 'home'
         | 
| 120 | 
            +
                puts "Benji's home!"
         | 
| 83 121 | 
             
              end
         | 
| 84 122 |  | 
| 85 123 | 
             
            </pre>
         | 
| 86 124 |  | 
| 87 | 
            -
             | 
| 125 | 
            +
            Whew. That's enough for now. But looking for a specific feature? Check out the rspecs,
         | 
| 126 | 
            +
            there are examples of nearly everything!
         | 
| 88 127 |  | 
| 89 128 |  | 
| 90 129 | 
             
            ## Contributing
         | 
| @@ -35,11 +35,11 @@ module Usergrid | |
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 37 | 
             
                def create_entity(data)
         | 
| 38 | 
            -
                   | 
| 39 | 
            -
                  response.entity
         | 
| 38 | 
            +
                  self.post data
         | 
| 40 39 | 
             
                end
         | 
| 40 | 
            +
                alias_method :create_entities, :create_entity
         | 
| 41 41 |  | 
| 42 | 
            -
                 | 
| 42 | 
            +
                ## options: 'reversed', 'start', 'cursor', 'limit', 'permission'
         | 
| 43 43 | 
             
                #def update(new_data, query=nil, options={}) # todo: enable when server is fixed
         | 
| 44 44 | 
             
                #  options = options.symbolize_keys
         | 
| 45 45 | 
             
                #  @query_params = query ? options.merge({ql: query}) : options
         | 
    
        data/lib/usergrid/core/entity.rb
    CHANGED
    
    
| @@ -1,12 +1,17 @@ | |
| 1 1 | 
             
            module Usergrid
         | 
| 2 2 | 
             
              class Management < Resource
         | 
| 3 3 |  | 
| 4 | 
            -
                def initialize( | 
| 5 | 
            -
                   | 
| 4 | 
            +
                def initialize(url, options={})
         | 
| 5 | 
            +
                  management = url.split('/')[-1]
         | 
| 6 | 
            +
                  if management == 'management'
         | 
| 7 | 
            +
                    api_url = url[0..url.index(management)-2]
         | 
| 8 | 
            +
                  else
         | 
| 9 | 
            +
                    api_url = url
         | 
| 10 | 
            +
                    url = concat_urls(api_url, 'management')
         | 
| 11 | 
            +
                  end
         | 
| 6 12 | 
             
                  super url, api_url, options
         | 
| 7 13 | 
             
                end
         | 
| 8 14 |  | 
| 9 | 
            -
                # one way: cannot delete organizations
         | 
| 10 15 | 
             
                def create_organization(organization, username, name, email, password)
         | 
| 11 16 | 
             
                  data = { organization: organization,
         | 
| 12 17 | 
             
                           username: username,
         | 
| @@ -22,7 +27,7 @@ module Usergrid | |
| 22 27 |  | 
| 23 28 | 
             
                def organization(organization)
         | 
| 24 29 | 
             
                  url = self["organizations/#{organization}"].url
         | 
| 25 | 
            -
                  Organization.new url,  | 
| 30 | 
            +
                  Organization.new url, options
         | 
| 26 31 | 
             
                end
         | 
| 27 32 |  | 
| 28 33 | 
             
                def users
         | 
| @@ -2,7 +2,9 @@ require 'uri' | |
| 2 2 | 
             
            module Usergrid
         | 
| 3 3 | 
             
              class Organization < Resource
         | 
| 4 4 |  | 
| 5 | 
            -
                def initialize(url,  | 
| 5 | 
            +
                def initialize(url, options={})
         | 
| 6 | 
            +
                  org_name = url.split('/')[-1]
         | 
| 7 | 
            +
                  api_url = url[0..url.index('management')-2]
         | 
| 6 8 | 
             
                  super url, api_url, options
         | 
| 7 9 | 
             
                end
         | 
| 8 10 |  | 
| @@ -24,7 +26,7 @@ module Usergrid | |
| 24 26 | 
             
                end
         | 
| 25 27 |  | 
| 26 28 | 
             
                def application(name_or_uuid)
         | 
| 27 | 
            -
                  Usergrid::Application.new concat_urls(api_url, "#{name}/#{name_or_uuid}"),  | 
| 29 | 
            +
                  Usergrid::Application.new concat_urls(api_url, "#{name}/#{name_or_uuid}"), options
         | 
| 28 30 | 
             
                end
         | 
| 29 31 |  | 
| 30 32 | 
             
                def users(query=nil)
         | 
| @@ -43,7 +43,7 @@ module Usergrid | |
| 43 43 |  | 
| 44 44 | 
             
                # application defaults to sandbox if none provided
         | 
| 45 45 | 
             
                def application(organization, application='sandbox')
         | 
| 46 | 
            -
                  Usergrid::Application.new concat_urls(api_url, "#{organization}/#{application}"),  | 
| 46 | 
            +
                  Usergrid::Application.new concat_urls(api_url, "#{organization}/#{application}"), options
         | 
| 47 47 | 
             
                end
         | 
| 48 48 |  | 
| 49 49 | 
             
                def query(query=nil, options={})
         | 
    
        data/lib/usergrid/version.rb
    CHANGED
    
    
| 
            File without changes
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
| @@ -258,7 +258,7 @@ describe Usergrid::Application do | |
| 258 258 | 
             
                roles.size.should == size
         | 
| 259 259 | 
             
              end
         | 
| 260 260 |  | 
| 261 | 
            -
              it "should be able to create a new collection and access it" do | 
| 261 | 
            +
              it "should be able to create a new collection and access it" do
         | 
| 262 262 | 
             
                entities = (1..4).collect do |i|
         | 
| 263 263 | 
             
                  { name: "test_#{i}" }
         | 
| 264 264 | 
             
                end
         | 
| @@ -2,16 +2,15 @@ describe Usergrid::Collection do | |
| 2 2 |  | 
| 3 3 | 
             
              before :all do
         | 
| 4 4 | 
             
                @application = create_random_application
         | 
| 5 | 
            +
                @user = create_random_user @application, true
         | 
| 5 6 |  | 
| 6 7 | 
             
                @collection = @application['tests'].collection
         | 
| 7 8 | 
             
                @entity_data = []
         | 
| 8 9 | 
             
                (1..10).each do |i|
         | 
| 9 10 | 
             
                  test = { name: "test_#{i}" }
         | 
| 10 11 | 
             
                  @entity_data << test
         | 
| 11 | 
            -
                  @collection.create_entity test
         | 
| 12 12 | 
             
                end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                @user = create_random_user @application, true
         | 
| 13 | 
            +
                @collection.create_entities @entity_data
         | 
| 15 14 | 
             
              end
         | 
| 16 15 |  | 
| 17 16 | 
             
              after :all do
         | 
| @@ -4,7 +4,7 @@ describe Hash do | |
| 4 4 |  | 
| 5 5 | 
             
              it "should add dot notation recursively" do
         | 
| 6 6 | 
             
                h = { test1: 'test1', test2: { test2a: 'test2a' }, test3: [ { test3a: 'test3a' }] }
         | 
| 7 | 
            -
                expect { h.test1 }. | 
| 7 | 
            +
                expect { h.test1 }.to raise_error
         | 
| 8 8 | 
             
                h.add_dot_notation!
         | 
| 9 9 | 
             
                h.test1.should eq 'test1'
         | 
| 10 10 | 
             
                h.test2.test2a.should eq 'test2a'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: usergrid_iron
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012-09- | 
| 12 | 
            +
            date: 2012-09-22 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: rest-client
         | 
| @@ -115,7 +115,6 @@ files: | |
| 115 115 | 
             
            - bin/ldiff
         | 
| 116 116 | 
             
            - bin/restclient
         | 
| 117 117 | 
             
            - bin/rspec
         | 
| 118 | 
            -
            - lib/usergrid.rb
         | 
| 119 118 | 
             
            - lib/usergrid/core/application.rb
         | 
| 120 119 | 
             
            - lib/usergrid/core/collection.rb
         | 
| 121 120 | 
             
            - lib/usergrid/core/entity.rb
         | 
| @@ -125,6 +124,7 @@ files: | |
| 125 124 | 
             
            - lib/usergrid/extensions/hash.rb
         | 
| 126 125 | 
             
            - lib/usergrid/extensions/response.rb
         | 
| 127 126 | 
             
            - lib/usergrid/version.rb
         | 
| 127 | 
            +
            - lib/usergrid_iron.rb
         | 
| 128 128 | 
             
            - spec/spec_helper.rb
         | 
| 129 129 | 
             
            - spec/spec_settings.yaml
         | 
| 130 130 | 
             
            - spec/usergrid/core/application_spec.rb
         | 
| @@ -149,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 149 149 | 
             
                  version: '0'
         | 
| 150 150 | 
             
                  segments:
         | 
| 151 151 | 
             
                  - 0
         | 
| 152 | 
            -
                  hash: - | 
| 152 | 
            +
                  hash: -4175816790877245614
         | 
| 153 153 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 154 154 | 
             
              none: false
         | 
| 155 155 | 
             
              requirements:
         | 
| @@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 158 158 | 
             
                  version: '0'
         | 
| 159 159 | 
             
                  segments:
         | 
| 160 160 | 
             
                  - 0
         | 
| 161 | 
            -
                  hash: - | 
| 161 | 
            +
                  hash: -4175816790877245614
         | 
| 162 162 | 
             
            requirements: []
         | 
| 163 163 | 
             
            rubyforge_project: 
         | 
| 164 164 | 
             
            rubygems_version: 1.8.24
         |