ncmb-ruby-client 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/examples/acl_test.rb +49 -0
 - data/examples/data_store.rb +1 -1
 - data/examples/user_test.rb +0 -4
 - data/lib/ncmb/acl.rb +41 -0
 - data/lib/ncmb/client.rb +12 -12
 - data/lib/ncmb/data_store.rb +13 -5
 - data/lib/ncmb/geo_point.rb +5 -1
 - data/lib/ncmb/object.rb +31 -11
 - data/lib/ncmb/role.rb +35 -0
 - data/lib/ncmb/user.rb +6 -5
 - data/lib/ncmb/version.rb +1 -1
 - data/lib/ncmb.rb +2 -0
 - metadata +5 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 5070337bf5759d8e8612db60a27a99fbf846071c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8e3cc58ab2a7076b00a1ae606cf7d8916e0ff1e9
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2ef149bd509da1aa9453ca2a7f19a5a736a9857f9ed0880286f0276040ade20484bf19f1cb151466802bb6c9f5dd816fa437a0c122de6d53b93f80c4438c88e8
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c19ea27d7910c912e68fde7b9be91bbbaf53659a3a7f89e469026377ac888cc63fa326ac54619c8d07ba507dd0682e9be64ef707bc1d62e1533590c468686aa2
         
     | 
| 
         @@ -0,0 +1,49 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
         
     | 
| 
      
 2 
     | 
    
         
            +
            $:.unshift(File.dirname(__FILE__))
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'ncmb'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'yaml'
         
     | 
| 
      
 6 
     | 
    
         
            +
            yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
         
     | 
| 
      
 7 
     | 
    
         
            +
            NCMB.initialize application_key: yaml['application_key'],  client_key: yaml['client_key']
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            @users = []
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            @ids = [
         
     | 
| 
      
 12 
     | 
    
         
            +
              {id: 'testUser1', password: 'testPassword1'},
         
     | 
| 
      
 13 
     | 
    
         
            +
              {id: 'testUser2', password: 'testPassword2'}
         
     | 
| 
      
 14 
     | 
    
         
            +
            ]
         
     | 
| 
      
 15 
     | 
    
         
            +
            @ids.each do |hash|
         
     | 
| 
      
 16 
     | 
    
         
            +
              @user = NCMB::User.login(hash[:id], hash[:password])
         
     | 
| 
      
 17 
     | 
    
         
            +
              if @user
         
     | 
| 
      
 18 
     | 
    
         
            +
              else
         
     | 
| 
      
 19 
     | 
    
         
            +
                @user = NCMB::User.new
         
     | 
| 
      
 20 
     | 
    
         
            +
                @user.set('userName', hash[:id])
         
     | 
| 
      
 21 
     | 
    
         
            +
                @user.set('password', hash[:password])
         
     | 
| 
      
 22 
     | 
    
         
            +
                if @user.signUp
         
     | 
| 
      
 23 
     | 
    
         
            +
                else
         
     | 
| 
      
 24 
     | 
    
         
            +
                  puts "User create failed. #{@user.error.message}"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  exit
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
              @users << @user
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            @testData = NCMB::DataStore.new 'testData'
         
     | 
| 
      
 32 
     | 
    
         
            +
            @testData.delete_all
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            @item = @testData.new
         
     | 
| 
      
 35 
     | 
    
         
            +
            @item.Message = 'World'
         
     | 
| 
      
 36 
     | 
    
         
            +
            @item.acl.public('read', true)
         
     | 
| 
      
 37 
     | 
    
         
            +
            @item.acl.public('write', false)
         
     | 
| 
      
 38 
     | 
    
         
            +
            @item.acl.user(@users[0], 'read', true)
         
     | 
| 
      
 39 
     | 
    
         
            +
            @item.acl.user(@users[0], 'write', true)
         
     | 
| 
      
 40 
     | 
    
         
            +
            @role = NCMB::Role.find_or_create("manager2")
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            @item.acl.role(@role, 'read', true)
         
     | 
| 
      
 43 
     | 
    
         
            +
            @item.acl.role(@role, 'write', true)
         
     | 
| 
      
 44 
     | 
    
         
            +
            @item.save
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            @data = @testData.where('objectId', @item.objectId).limit(1).get
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            @user = NCMB::User.login(@ids[0][:id], @ids[0][:password])
         
     | 
| 
      
 49 
     | 
    
         
            +
            @testData.delete_all
         
     | 
    
        data/examples/data_store.rb
    CHANGED
    
    | 
         @@ -9,7 +9,7 @@ NCMB.initialize application_key: yaml['application_key'],  client_key: yaml['cli 
     | 
|
| 
       9 
9 
     | 
    
         
             
            example = NCMB::DataStore.new 'Example'
         
     | 
| 
       10 
10 
     | 
    
         
             
            example.delete_all
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
            9.times do |i|
         
     | 
| 
       13 
13 
     | 
    
         
             
              item = example.new
         
     | 
| 
       14 
14 
     | 
    
         
             
              item.set('String', "テスト#{i}00")
         
     | 
| 
       15 
15 
     | 
    
         
             
              item.set('Integer', i)
         
     | 
    
        data/examples/user_test.rb
    CHANGED
    
    
    
        data/lib/ncmb/acl.rb
    ADDED
    
    | 
         @@ -0,0 +1,41 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module NCMB
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Acl < NCMB::Object
         
     | 
| 
      
 3 
     | 
    
         
            +
                include NCMB
         
     | 
| 
      
 4 
     | 
    
         
            +
                
         
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(params = nil)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @fields = {'*': {
         
     | 
| 
      
 7 
     | 
    
         
            +
                      read: true,
         
     | 
| 
      
 8 
     | 
    
         
            +
                      write: true
         
     | 
| 
      
 9 
     | 
    
         
            +
                    }
         
     | 
| 
      
 10 
     | 
    
         
            +
                  }
         
     | 
| 
      
 11 
     | 
    
         
            +
                  if params
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @fields = @fields.merge(params)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
                
         
     | 
| 
      
 16 
     | 
    
         
            +
                def to_json(a = "")
         
     | 
| 
      
 17 
     | 
    
         
            +
                  params = {}
         
     | 
| 
      
 18 
     | 
    
         
            +
                  @fields.each do |key, value|
         
     | 
| 
      
 19 
     | 
    
         
            +
                    params[key.to_sym] = {} if value[:read] || value[:write]
         
     | 
| 
      
 20 
     | 
    
         
            +
                    [:read, :write].each do |name|
         
     | 
| 
      
 21 
     | 
    
         
            +
                      params[key.to_sym][name] = true if value[name]
         
     | 
| 
      
 22 
     | 
    
         
            +
                    end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
                  params.to_json
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
                
         
     | 
| 
      
 27 
     | 
    
         
            +
                def public(read_or_write, value = true)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @fields['*'.to_sym][read_or_write.to_sym] = value
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
                
         
     | 
| 
      
 31 
     | 
    
         
            +
                def user(user, read_or_write, value = true)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @fields[user.objectId.to_sym] = {read: true, write: true} unless @fields[user.objectId.to_sym]
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @fields[user.objectId.to_sym][read_or_write.to_sym] = value
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
                
         
     | 
| 
      
 36 
     | 
    
         
            +
                def role(role, read_or_write, value = true)
         
     | 
| 
      
 37 
     | 
    
         
            +
                  @fields[role.name.to_sym] = {read: true, write: true} unless @fields[role.name.to_sym]
         
     | 
| 
      
 38 
     | 
    
         
            +
                  @fields[role.name.to_sym][read_or_write.to_sym] = value
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/ncmb/client.rb
    CHANGED
    
    | 
         @@ -24,20 +24,20 @@ module NCMB 
     | 
|
| 
       24 
24 
     | 
    
         
             
                  @client_key      = params[:client_key]
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                def get(path, params = {} 
     | 
| 
       28 
     | 
    
         
            -
                  request :get, path, params 
     | 
| 
      
 27 
     | 
    
         
            +
                def get(path, params = {})
         
     | 
| 
      
 28 
     | 
    
         
            +
                  request :get, path, params
         
     | 
| 
       29 
29 
     | 
    
         
             
                end
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                def post(path, params = {} 
     | 
| 
       32 
     | 
    
         
            -
                  request :post, path, params 
     | 
| 
      
 31 
     | 
    
         
            +
                def post(path, params = {})
         
     | 
| 
      
 32 
     | 
    
         
            +
                  request :post, path, params
         
     | 
| 
       33 
33 
     | 
    
         
             
                end
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
                def put(path, params = {} 
     | 
| 
       36 
     | 
    
         
            -
                  request :put, path, params 
     | 
| 
      
 35 
     | 
    
         
            +
                def put(path, params = {})
         
     | 
| 
      
 36 
     | 
    
         
            +
                  request :put, path, params
         
     | 
| 
       37 
37 
     | 
    
         
             
                end
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                def delete(path, params = {} 
     | 
| 
       40 
     | 
    
         
            -
                  request :delete, path, params 
     | 
| 
      
 39 
     | 
    
         
            +
                def delete(path, params = {})
         
     | 
| 
      
 40 
     | 
    
         
            +
                  request :delete, path, params
         
     | 
| 
       41 
41 
     | 
    
         
             
                end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
                def array2hash(ary)
         
     | 
| 
         @@ -118,7 +118,7 @@ module NCMB 
     | 
|
| 
       118 
118 
     | 
    
         
             
                  signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @client_key, signature_base.join("\n"))).strip()
         
     | 
| 
       119 
119 
     | 
    
         
             
                end
         
     | 
| 
       120 
120 
     | 
    
         | 
| 
       121 
     | 
    
         
            -
                def request(method, path, queries = {} 
     | 
| 
      
 121 
     | 
    
         
            +
                def request(method, path, queries = {})
         
     | 
| 
       122 
122 
     | 
    
         
             
                  now = Time.now.utc.iso8601
         
     | 
| 
       123 
123 
     | 
    
         
             
                  signature = generate_signature(method, path, now, queries)
         
     | 
| 
       124 
124 
     | 
    
         
             
                  http = Net::HTTP.new(@domain, 443)
         
     | 
| 
         @@ -129,12 +129,11 @@ module NCMB 
     | 
|
| 
       129 
129 
     | 
    
         
             
                    "X-NCMB-Timestamp" => now,
         
     | 
| 
       130 
130 
     | 
    
         
             
                    "Content-Type" => 'application/json'
         
     | 
| 
       131 
131 
     | 
    
         
             
                  }
         
     | 
| 
       132 
     | 
    
         
            -
                  if  
     | 
| 
       133 
     | 
    
         
            -
                    headers['X-NCMB-Apps-Session-Token'] =  
     | 
| 
      
 132 
     | 
    
         
            +
                  if NCMB.CurrentUser
         
     | 
| 
      
 133 
     | 
    
         
            +
                    headers['X-NCMB-Apps-Session-Token'] = NCMB.CurrentUser.sessionToken
         
     | 
| 
       134 
134 
     | 
    
         
             
                  end
         
     | 
| 
       135 
135 
     | 
    
         
             
                  # queries = hash2query(queries)
         
     | 
| 
       136 
136 
     | 
    
         
             
                  json = nil
         
     | 
| 
       137 
     | 
    
         
            -
                  begin
         
     | 
| 
       138 
137 
     | 
    
         
             
                    case method
         
     | 
| 
       139 
138 
     | 
    
         
             
                    when :get
         
     | 
| 
       140 
139 
     | 
    
         
             
                      query = encode_query(queries).map do |key, value|
         
     | 
| 
         @@ -152,6 +151,7 @@ module NCMB 
     | 
|
| 
       152 
151 
     | 
    
         
             
                      return true if response == ""
         
     | 
| 
       153 
152 
     | 
    
         
             
                      json = JSON.parse(response, symbolize_names: true)
         
     | 
| 
       154 
153 
     | 
    
         
             
                    end
         
     | 
| 
      
 154 
     | 
    
         
            +
                    begin
         
     | 
| 
       155 
155 
     | 
    
         
             
                  rescue => e
         
     | 
| 
       156 
156 
     | 
    
         
             
                    @@last_error =  e
         
     | 
| 
       157 
157 
     | 
    
         
             
                    raise NCMB::APIError.new(e.to_s)
         
     | 
    
        data/lib/ncmb/data_store.rb
    CHANGED
    
    | 
         @@ -8,7 +8,9 @@ module NCMB 
     | 
|
| 
       8 
8 
     | 
    
         
             
                  @fields  = fields
         
     | 
| 
       9 
9 
     | 
    
         
             
                  @queries = {where: []}
         
     | 
| 
       10 
10 
     | 
    
         
             
                  @items   = nil
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @path    = nil
         
     | 
| 
       11 
12 
     | 
    
         
             
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
                attr_accessor :path
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
15 
     | 
    
         
             
                def error
         
     | 
| 
       14 
16 
     | 
    
         
             
                  @error
         
     | 
| 
         @@ -131,9 +133,13 @@ module NCMB 
     | 
|
| 
       131 
133 
     | 
    
         
             
                  get[count]
         
     | 
| 
       132 
134 
     | 
    
         
             
                end
         
     | 
| 
       133 
135 
     | 
    
         | 
| 
      
 136 
     | 
    
         
            +
                def path
         
     | 
| 
      
 137 
     | 
    
         
            +
                  return @path if @path
         
     | 
| 
      
 138 
     | 
    
         
            +
                  path = "/#{@@client.api_version}/classes/#{@name}"
         
     | 
| 
      
 139 
     | 
    
         
            +
                end
         
     | 
| 
      
 140 
     | 
    
         
            +
                
         
     | 
| 
       134 
141 
     | 
    
         
             
                def get
         
     | 
| 
       135 
142 
     | 
    
         
             
                  return @items unless @items.nil?
         
     | 
| 
       136 
     | 
    
         
            -
                  path = "/#{@@client.api_version}/classes/#{@name}"
         
     | 
| 
       137 
143 
     | 
    
         
             
                  results = @@client.get path, @queries
         
     | 
| 
       138 
144 
     | 
    
         
             
                  return [] unless results
         
     | 
| 
       139 
145 
     | 
    
         
             
                  if results[:error] && results[:error] != ""
         
     | 
| 
         @@ -153,9 +159,7 @@ module NCMB 
     | 
|
| 
       153 
159 
     | 
    
         
             
                        result[key] = Time.parse(field[:iso])
         
     | 
| 
       154 
160 
     | 
    
         
             
                      end
         
     | 
| 
       155 
161 
     | 
    
         
             
                    end
         
     | 
| 
       156 
     | 
    
         
            -
                     
     | 
| 
       157 
     | 
    
         
            -
                    result.delete(:acl)
         
     | 
| 
       158 
     | 
    
         
            -
                    @items << NCMB::Object.new(@name, result, alc)
         
     | 
| 
      
 162 
     | 
    
         
            +
                    @items << NCMB::Object.new(@name, result)
         
     | 
| 
       159 
163 
     | 
    
         
             
                  end
         
     | 
| 
       160 
164 
     | 
    
         
             
                  @items
         
     | 
| 
       161 
165 
     | 
    
         
             
                end
         
     | 
| 
         @@ -174,7 +178,11 @@ module NCMB 
     | 
|
| 
       174 
178 
     | 
    
         
             
                  end
         
     | 
| 
       175 
179 
     | 
    
         
             
                  dataStore.queries.delete :count
         
     | 
| 
       176 
180 
     | 
    
         
             
                  dataStore.each do |item|
         
     | 
| 
       177 
     | 
    
         
            -
                     
     | 
| 
      
 181 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 182 
     | 
    
         
            +
                      item.delete if item.deletable?
         
     | 
| 
      
 183 
     | 
    
         
            +
                    rescue
         
     | 
| 
      
 184 
     | 
    
         
            +
                      puts "Can't delete #{item.objectId}"
         
     | 
| 
      
 185 
     | 
    
         
            +
                    end
         
     | 
| 
       178 
186 
     | 
    
         
             
                  end
         
     | 
| 
       179 
187 
     | 
    
         
             
                  if count > max
         
     | 
| 
       180 
188 
     | 
    
         
             
                    return delete_all
         
     | 
    
        data/lib/ncmb/geo_point.rb
    CHANGED
    
    
    
        data/lib/ncmb/object.rb
    CHANGED
    
    | 
         @@ -2,9 +2,9 @@ module NCMB 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Object
         
     | 
| 
       3 
3 
     | 
    
         
             
                include NCMB
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
                def initialize(name, fields = {} 
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(name, fields = {})
         
     | 
| 
       6 
6 
     | 
    
         
             
                  @name    = name
         
     | 
| 
       7 
     | 
    
         
            -
                   
     | 
| 
      
 7 
     | 
    
         
            +
                  fields[:acl] = NCMB::Acl.new(fields[:acl])
         
     | 
| 
       8 
8 
     | 
    
         
             
                  @fields  = fields
         
     | 
| 
       9 
9 
     | 
    
         
             
                end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
         @@ -12,12 +12,17 @@ module NCMB 
     | 
|
| 
       12 
12 
     | 
    
         
             
                  @fields
         
     | 
| 
       13 
13 
     | 
    
         
             
                end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                def method_missing(name)
         
     | 
| 
       16 
     | 
    
         
            -
                   
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                     
     | 
| 
      
 15 
     | 
    
         
            +
                def method_missing(name, value = nil)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  if name =~ /.*=$/
         
     | 
| 
      
 17 
     | 
    
         
            +
                    sym = name.to_s.gsub(/(.*?)=$/, '\1').to_sym
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @fields[sym] = value
         
     | 
| 
       19 
19 
     | 
    
         
             
                  else
         
     | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
      
 20 
     | 
    
         
            +
                    sym = name.to_sym
         
     | 
| 
      
 21 
     | 
    
         
            +
                    if @fields.has_key?(sym)
         
     | 
| 
      
 22 
     | 
    
         
            +
                      return @fields[sym]
         
     | 
| 
      
 23 
     | 
    
         
            +
                    else
         
     | 
| 
      
 24 
     | 
    
         
            +
                      raise NoMethodError, "#{name} is not found"
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
       21 
26 
     | 
    
         
             
                  end
         
     | 
| 
       22 
27 
     | 
    
         
             
                end
         
     | 
| 
       23 
28 
     | 
    
         | 
| 
         @@ -32,9 +37,26 @@ module NCMB 
     | 
|
| 
       32 
37 
     | 
    
         
             
                def [](key)
         
     | 
| 
       33 
38 
     | 
    
         
             
                  @fields[key]
         
     | 
| 
       34 
39 
     | 
    
         
             
                end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                
         
     | 
| 
      
 41 
     | 
    
         
            +
                def deletable?
         
     | 
| 
      
 42 
     | 
    
         
            +
                  if self.acl['*'.to_sym][:write] == true
         
     | 
| 
      
 43 
     | 
    
         
            +
                    return true
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                  return false unless NCMB.CurrentUser
         
     | 
| 
      
 46 
     | 
    
         
            +
                  return false unless self.acl[NCMB.CurrentUser.objectId.to_sym]
         
     | 
| 
      
 47 
     | 
    
         
            +
                  return false unless self.acl[NCMB.CurrentUser.objectId.to_sym][:write]
         
     | 
| 
      
 48 
     | 
    
         
            +
                  true
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
                
         
     | 
| 
      
 51 
     | 
    
         
            +
                def base_path
         
     | 
| 
      
 52 
     | 
    
         
            +
                  "/#{@@client.api_version}/classes/#{@name}"
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
                
         
     | 
| 
      
 55 
     | 
    
         
            +
                def path
         
     | 
| 
      
 56 
     | 
    
         
            +
                  "#{base_path}/#{@fields[:objectId] || '' }"
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
                
         
     | 
| 
       36 
59 
     | 
    
         
             
                def post
         
     | 
| 
       37 
     | 
    
         
            -
                  path = "/#{@@client.api_version}/classes/#{@name}"
         
     | 
| 
       38 
60 
     | 
    
         
             
                  result = @@client.post path, @fields
         
     | 
| 
       39 
61 
     | 
    
         
             
                  @fields.merge!(result)
         
     | 
| 
       40 
62 
     | 
    
         
             
                  self
         
     | 
| 
         @@ -42,7 +64,6 @@ module NCMB 
     | 
|
| 
       42 
64 
     | 
    
         
             
                alias :save :post
         
     | 
| 
       43 
65 
     | 
    
         | 
| 
       44 
66 
     | 
    
         
             
                def put
         
     | 
| 
       45 
     | 
    
         
            -
                  path = "/#{@@client.api_version}/classes/#{@name}/#{@fields[:objectId]}"
         
     | 
| 
       46 
67 
     | 
    
         
             
                  params = @fields
         
     | 
| 
       47 
68 
     | 
    
         
             
                  params.delete :objectId
         
     | 
| 
       48 
69 
     | 
    
         
             
                  params.delete :createDate
         
     | 
| 
         @@ -54,7 +75,6 @@ module NCMB 
     | 
|
| 
       54 
75 
     | 
    
         
             
                alias :update :put
         
     | 
| 
       55 
76 
     | 
    
         | 
| 
       56 
77 
     | 
    
         
             
                def delete
         
     | 
| 
       57 
     | 
    
         
            -
                  path = "/#{@@client.api_version}/classes/#{@name}/#{@fields[:objectId]}"
         
     | 
| 
       58 
78 
     | 
    
         
             
                  response = @@client.delete path, {}
         
     | 
| 
       59 
79 
     | 
    
         
             
                  if response == true
         
     | 
| 
       60 
80 
     | 
    
         
             
                    return true
         
     | 
    
        data/lib/ncmb/role.rb
    ADDED
    
    | 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module NCMB
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Role < NCMB::Object
         
     | 
| 
      
 3 
     | 
    
         
            +
                include NCMB
         
     | 
| 
      
 4 
     | 
    
         
            +
                
         
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(name)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  if name.is_a? Hash
         
     | 
| 
      
 7 
     | 
    
         
            +
                    @fields = name
         
     | 
| 
      
 8 
     | 
    
         
            +
                  else
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @fields = {
         
     | 
| 
      
 10 
     | 
    
         
            +
                      roleName: name
         
     | 
| 
      
 11 
     | 
    
         
            +
                    }
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
                
         
     | 
| 
      
 15 
     | 
    
         
            +
                def self.find_or_create(name)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  d = NCMB::DataStore.new('role')
         
     | 
| 
      
 17 
     | 
    
         
            +
                  d.path = NCMB::Role.new(name).base_path
         
     | 
| 
      
 18 
     | 
    
         
            +
                  role = d.where('roleName', name).limit(1).get.first
         
     | 
| 
      
 19 
     | 
    
         
            +
                  role ? NCMB::Role.new(role.fields) : NCMB::Role.new(name).save()
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
                
         
     | 
| 
      
 22 
     | 
    
         
            +
                def name
         
     | 
| 
      
 23 
     | 
    
         
            +
                  "role:#{@fields[:roleName]}"
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
                
         
     | 
| 
      
 26 
     | 
    
         
            +
                def to_json
         
     | 
| 
      
 27 
     | 
    
         
            +
                  
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
                
         
     | 
| 
      
 30 
     | 
    
         
            +
                def base_path
         
     | 
| 
      
 31 
     | 
    
         
            +
                  path = "/#{@@client.api_version}/roles"
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
                
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/ncmb/user.rb
    CHANGED
    
    | 
         @@ -2,12 +2,11 @@ module NCMB 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class User < NCMB::Object
         
     | 
| 
       3 
3 
     | 
    
         
             
                include NCMB
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
                def initialize(params = {} 
     | 
| 
       6 
     | 
    
         
            -
                  super('users', params 
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(params = {})
         
     | 
| 
      
 6 
     | 
    
         
            +
                  super('users', params)
         
     | 
| 
       7 
7 
     | 
    
         
             
                end
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                def signUp
         
     | 
| 
       10 
     | 
    
         
            -
                  path = "/#{@@client.api_version}/#{@name}"
         
     | 
| 
       11 
10 
     | 
    
         
             
                  begin
         
     | 
| 
       12 
11 
     | 
    
         
             
                    result = @@client.post path, @fields
         
     | 
| 
       13 
12 
     | 
    
         
             
                  rescue => e
         
     | 
| 
         @@ -19,8 +18,11 @@ module NCMB 
     | 
|
| 
       19 
18 
     | 
    
         
             
                  self
         
     | 
| 
       20 
19 
     | 
    
         
             
                end
         
     | 
| 
       21 
20 
     | 
    
         | 
| 
      
 21 
     | 
    
         
            +
                def base_path
         
     | 
| 
      
 22 
     | 
    
         
            +
                  path = "/#{@@client.api_version}/#{@name}"
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
                
         
     | 
| 
       22 
25 
     | 
    
         
             
                def put
         
     | 
| 
       23 
     | 
    
         
            -
                  path = "/#{@@client.api_version}/#{@name}/#{@fields[:objectId]}"
         
     | 
| 
       24 
26 
     | 
    
         
             
                  params = @fields
         
     | 
| 
       25 
27 
     | 
    
         
             
                  session_key = params[:sessionToken]
         
     | 
| 
       26 
28 
     | 
    
         
             
                  [:objectId, :createDate, :updateDate, :sessionToken, :password].each do |name|
         
     | 
| 
         @@ -33,7 +35,6 @@ module NCMB 
     | 
|
| 
       33 
35 
     | 
    
         
             
                alias :update :put
         
     | 
| 
       34 
36 
     | 
    
         | 
| 
       35 
37 
     | 
    
         
             
                def delete
         
     | 
| 
       36 
     | 
    
         
            -
                  path = "/#{@@client.api_version}/#{@name}/#{@fields[:objectId]}"
         
     | 
| 
       37 
38 
     | 
    
         
             
                  response = @@client.delete path, {}, @fields[:sessionToken]
         
     | 
| 
       38 
39 
     | 
    
         
             
                  if response == true
         
     | 
| 
       39 
40 
     | 
    
         
             
                    @@current_user = nil
         
     | 
    
        data/lib/ncmb/version.rb
    CHANGED
    
    
    
        data/lib/ncmb.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: ncmb-ruby-client
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Atsushi Nakatsugawa
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2016-09- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-09-10 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -64,6 +64,7 @@ files: 
     | 
|
| 
       64 
64 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       65 
65 
     | 
    
         
             
            - README.md
         
     | 
| 
       66 
66 
     | 
    
         
             
            - Rakefile
         
     | 
| 
      
 67 
     | 
    
         
            +
            - examples/acl_test.rb
         
     | 
| 
       67 
68 
     | 
    
         
             
            - examples/csv_test.rb
         
     | 
| 
       68 
69 
     | 
    
         
             
            - examples/data_store.rb
         
     | 
| 
       69 
70 
     | 
    
         
             
            - examples/push.rb
         
     | 
| 
         @@ -72,6 +73,7 @@ files: 
     | 
|
| 
       72 
73 
     | 
    
         
             
            - examples/venue_search.rb
         
     | 
| 
       73 
74 
     | 
    
         
             
            - examples/venues.json
         
     | 
| 
       74 
75 
     | 
    
         
             
            - lib/ncmb.rb
         
     | 
| 
      
 76 
     | 
    
         
            +
            - lib/ncmb/acl.rb
         
     | 
| 
       75 
77 
     | 
    
         
             
            - lib/ncmb/client.rb
         
     | 
| 
       76 
78 
     | 
    
         
             
            - lib/ncmb/data_store.rb
         
     | 
| 
       77 
79 
     | 
    
         
             
            - lib/ncmb/device.rb
         
     | 
| 
         @@ -80,6 +82,7 @@ files: 
     | 
|
| 
       80 
82 
     | 
    
         
             
            - lib/ncmb/increment.rb
         
     | 
| 
       81 
83 
     | 
    
         
             
            - lib/ncmb/object.rb
         
     | 
| 
       82 
84 
     | 
    
         
             
            - lib/ncmb/push.rb
         
     | 
| 
      
 85 
     | 
    
         
            +
            - lib/ncmb/role.rb
         
     | 
| 
       83 
86 
     | 
    
         
             
            - lib/ncmb/user.rb
         
     | 
| 
       84 
87 
     | 
    
         
             
            - lib/ncmb/version.rb
         
     | 
| 
       85 
88 
     | 
    
         
             
            - ncmb-ruby-client.gemspec
         
     |