Sha256: 6adebd0f505dd09559486fd2ad4fdf53d264afd3f0f9cbeb4404f2228fe58037

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'leancloud/protocol'
require 'leancloud/client'
require 'leancloud/error'
require 'leancloud/object'

module AV
  class Installation < AV::Object
    UPDATABLE_FIELDS = {
      badge: 'badge',
      channels: 'channels',
      time_zone: 'timeZone',
      device_token: 'deviceToken',
      channel_uris: 'channelUris',
      app_name: 'appName',
      app_version: 'appVersion',
      parse_version: 'parseVersion',
      app_identifier: 'appIdentifier'
    }

    def initialize(parse_object_id)
      @parse_object_id = parse_object_id
    end

    def self.get(parse_object_id)
      new(parse_object_id).get
    end

    def get
      if response = AV.client.request(uri, :get, nil, nil)
        parse AV.parse_json(nil, response)
      end
    end

    UPDATABLE_FIELDS.each do |method_name, key|
      define_method "#{method_name}=" do |value|
        self[key] = value
      end
    end

    def uri
      Protocol.installation_uri @parse_object_id
    end

    def save
      AV.client.request uri, method, self.to_json, nil
    end

    def rest_api_hash
      self
    end

    def method
      @parse_object_id ? :put : :post
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
leancloud-ruby-client-0.1.1 lib/leancloud/installation.rb
leancloud-ruby-client-0.1.0 lib/leancloud/installation.rb