=begin #カラーミーショップ API ## カラーミーショップ API [カラーミーショップ](https://shop-pro.jp) APIでは、受注の検索や商品情報の更新を行うことができます。 ## 利用手順 はじめに、カラーミーデベロッパーアカウントを用意します。[デベロッパー登録ページ](https://api.shop-pro.jp/developers/sign_up)から登録してください。 次に、[登録ページ](https://api.shop-pro.jp/oauth/applications/new)からアプリケーション登録を行ってください。 スマートフォンのWebViewを利用する場合は、リダイレクトURLに`urn:ietf:wg:oauth:2.0:oob`を入力してください。 その後、カラーミーショップアカウントの認証ページを開きます。認証ページのURLは、`https://api.shop-pro.jp/oauth/authorize`に必要なパラメータをつけたものです。 |パラメータ名|値| |---|---| |`client_id`|アプリケーション詳細画面で確認できるクライアントID| |`response_type`|\"code\"という文字列| |`scope`| 別表参照| |`redirect_url`|アプリケーション登録時に入力したリダイレクトURL| `scope`は、以下のうち、アプリケーションが利用したい機能をスペース区切りで指定してください。 |スコープ|機能| |---|---| |`read_products`|商品データの参照| |`write_products`|在庫データの更新| |`read_sales`|受注・顧客データの参照| |`write_sales`|受注データの更新| 以下のようなURLとなります。 ``` https://api.shop-pro.jp/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URL&response_type=code&scope=read_products%20write_products ``` 初めてこのページを訪れる場合は、カラーミーショップアカウントのIDとパスワードの入力を求められます。 承認ボタンを押すと、このアプリケーションがショップのデータにアクセスすることが許可され、リダイレクトURLへリダイレクトされます。 承認された場合は、`code`というクエリパラメータに認可コードが付与されます。承認がキャンセルされた、またはエラーが起きた場合は、 `error`パラメータにエラーの内容を表す文字列が与えられます。 アプリケーション登録時のリダイレクトURLに`urn:ietf:wg:oauth:2.0:oob`を指定した場合は、以下のようなURLにリダイレクトされます。 末尾のパスが認可コードになっています。 ``` https://api.shop-pro.jp/oauth/authorize/AUTH_CODE ``` 認可コードの有効期限は発行から10分間です。 最後に、認可コードとアクセストークンを交換します。以下のパラメータを付けて、`https://api.shop-pro.jp/oauth/token`へリクエストを送ります。 |パラメータ名|値| |---|---| |`client_id`|アプリケーション詳細画面に表示されているクライアントID| |`client_secret`|アプリケーション詳細画面に表示されているクライアントシークレット| |`code`|取得した認可コード| |`grant_type`|\"authorization_code\"という文字列| |`redirect_uri`|アプリケーション登録時に入力したリダイレクトURL| ```console # curl での例 $ curl -X POST \\ -d'client_id=CLIENT_ID' \\ -d'client_secret=CLIENT_SECRET' \\ -d'code=CODE' \\ -d'grant_type=authorization_code' \\ -d'redirect_uri=REDIRECT_URI' \\ 'https://api.shop-pro.jp/oauth/token' ``` リクエストが成功すると、以下のようなJSONが返ってきます。 ```json { \"access_token\": \"d461ab8XXXXXXXXXXXXXXXXXXXXXXXXX\", \"token_type\": \"bearer\", \"scope\": \"read_products write_products\" } ``` アクセストークンに有効期限はありませんが、許可済みアプリケーション一覧画面から失効させることができます。なお、同じ認可コードをアクセストークンに交換できるのは1度だけです。 取得したアクセストークンは、Authorizationヘッダに入れて使用します。以下にショップ情報を取得する際の例を示します。 ```console # curlの例 $ curl -H 'Authorization: Bearer d461ab8XXXXXXXXXXXXXXXXXXXXXXXXX' https://api.shop-pro.jp/v1/shop.json ``` ## エラー カラーミーショップAPI v1では - エラーコード - エラーメッセージ - ステータスコード の配列でエラーを表現します。以下に例を示します。 ```json { \"errors\": [ { \"code\": 404100, \"message\": \"レコードが見つかりませんでした。\", \"status\": 404 } ] } ``` OpenAPI spec version: 1.0.0 Generated by: https://openapi-generator.tech OpenAPI Generator version: 3.2.0-SNAPSHOT =end require 'date' module ColorMeShop class SaleDelivery # 配送ID attr_accessor :id # ショップアカウントID attr_accessor :account_id # 売上ID attr_accessor :sale_id # 使用された配送方法ID attr_accessor :delivery_id # この配送に含まれる受注明細IDの配列 attr_accessor :detail_ids # 宛名 attr_accessor :name # 宛名のフリガナ attr_accessor :furigana # 郵便番号 attr_accessor :postal # 都道府県の通し番号。北海道が1、沖縄が47 attr_accessor :pref_id # 都道府県名 attr_accessor :pref_name # 住所1 attr_accessor :address1 # 住所2 attr_accessor :address2 # 電話番号 attr_accessor :tel # 配送希望日 attr_accessor :preferred_date # 配送希望時間帯 attr_accessor :preferred_period # 配送伝票番号 attr_accessor :slip_number # 熨斗の文言 attr_accessor :noshi_text # 熨斗の料金 attr_accessor :noshi_charge # メッセージカードの表示名 attr_accessor :card_name # メッセージカードのテキスト attr_accessor :card_text # メッセージカードの料金 attr_accessor :card_charge # ラッピングの表示名 attr_accessor :wrapping_name # ラッピングの料金 attr_accessor :wrapping_charge # 配送料 attr_accessor :delivery_charge # 配送料・手数料の小計 attr_accessor :total_charge # 備考 attr_accessor :memo # 発送済みであるか否か attr_accessor :delivered # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { :'id' => :'id', :'account_id' => :'account_id', :'sale_id' => :'sale_id', :'delivery_id' => :'delivery_id', :'detail_ids' => :'detail_ids', :'name' => :'name', :'furigana' => :'furigana', :'postal' => :'postal', :'pref_id' => :'pref_id', :'pref_name' => :'pref_name', :'address1' => :'address1', :'address2' => :'address2', :'tel' => :'tel', :'preferred_date' => :'preferred_date', :'preferred_period' => :'preferred_period', :'slip_number' => :'slip_number', :'noshi_text' => :'noshi_text', :'noshi_charge' => :'noshi_charge', :'card_name' => :'card_name', :'card_text' => :'card_text', :'card_charge' => :'card_charge', :'wrapping_name' => :'wrapping_name', :'wrapping_charge' => :'wrapping_charge', :'delivery_charge' => :'delivery_charge', :'total_charge' => :'total_charge', :'memo' => :'memo', :'delivered' => :'delivered' } end # Attribute type mapping. def self.openapi_types { :'id' => :'Integer', :'account_id' => :'String', :'sale_id' => :'Integer', :'delivery_id' => :'Integer', :'detail_ids' => :'Array', :'name' => :'String', :'furigana' => :'String', :'postal' => :'String', :'pref_id' => :'Integer', :'pref_name' => :'String', :'address1' => :'String', :'address2' => :'String', :'tel' => :'String', :'preferred_date' => :'String', :'preferred_period' => :'String', :'slip_number' => :'String', :'noshi_text' => :'String', :'noshi_charge' => :'Integer', :'card_name' => :'String', :'card_text' => :'String', :'card_charge' => :'Integer', :'wrapping_name' => :'String', :'wrapping_charge' => :'Integer', :'delivery_charge' => :'Integer', :'total_charge' => :'Integer', :'memo' => :'String', :'delivered' => :'BOOLEAN' } end # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) return unless attributes.is_a?(Hash) # convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } if attributes.has_key?(:'id') self.id = attributes[:'id'] end if attributes.has_key?(:'account_id') self.account_id = attributes[:'account_id'] end if attributes.has_key?(:'sale_id') self.sale_id = attributes[:'sale_id'] end if attributes.has_key?(:'delivery_id') self.delivery_id = attributes[:'delivery_id'] end if attributes.has_key?(:'detail_ids') if (value = attributes[:'detail_ids']).is_a?(Array) self.detail_ids = value end end if attributes.has_key?(:'name') self.name = attributes[:'name'] end if attributes.has_key?(:'furigana') self.furigana = attributes[:'furigana'] end if attributes.has_key?(:'postal') self.postal = attributes[:'postal'] end if attributes.has_key?(:'pref_id') self.pref_id = attributes[:'pref_id'] end if attributes.has_key?(:'pref_name') self.pref_name = attributes[:'pref_name'] end if attributes.has_key?(:'address1') self.address1 = attributes[:'address1'] end if attributes.has_key?(:'address2') self.address2 = attributes[:'address2'] end if attributes.has_key?(:'tel') self.tel = attributes[:'tel'] end if attributes.has_key?(:'preferred_date') self.preferred_date = attributes[:'preferred_date'] end if attributes.has_key?(:'preferred_period') self.preferred_period = attributes[:'preferred_period'] end if attributes.has_key?(:'slip_number') self.slip_number = attributes[:'slip_number'] end if attributes.has_key?(:'noshi_text') self.noshi_text = attributes[:'noshi_text'] end if attributes.has_key?(:'noshi_charge') self.noshi_charge = attributes[:'noshi_charge'] end if attributes.has_key?(:'card_name') self.card_name = attributes[:'card_name'] end if attributes.has_key?(:'card_text') self.card_text = attributes[:'card_text'] end if attributes.has_key?(:'card_charge') self.card_charge = attributes[:'card_charge'] end if attributes.has_key?(:'wrapping_name') self.wrapping_name = attributes[:'wrapping_name'] end if attributes.has_key?(:'wrapping_charge') self.wrapping_charge = attributes[:'wrapping_charge'] end if attributes.has_key?(:'delivery_charge') self.delivery_charge = attributes[:'delivery_charge'] end if attributes.has_key?(:'total_charge') self.total_charge = attributes[:'total_charge'] end if attributes.has_key?(:'memo') self.memo = attributes[:'memo'] end if attributes.has_key?(:'delivered') self.delivered = attributes[:'delivered'] end end # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties invalid_properties = Array.new invalid_properties end # Check to see if the all the properties in the model are valid # @return true if the model is valid def valid? true end # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) return true if self.equal?(o) self.class == o.class && id == o.id && account_id == o.account_id && sale_id == o.sale_id && delivery_id == o.delivery_id && detail_ids == o.detail_ids && name == o.name && furigana == o.furigana && postal == o.postal && pref_id == o.pref_id && pref_name == o.pref_name && address1 == o.address1 && address2 == o.address2 && tel == o.tel && preferred_date == o.preferred_date && preferred_period == o.preferred_period && slip_number == o.slip_number && noshi_text == o.noshi_text && noshi_charge == o.noshi_charge && card_name == o.card_name && card_text == o.card_text && card_charge == o.card_charge && wrapping_name == o.wrapping_name && wrapping_charge == o.wrapping_charge && delivery_charge == o.delivery_charge && total_charge == o.total_charge && memo == o.memo && delivered == o.delivered end # @see the `==` method # @param [Object] Object to be compared def eql?(o) self == o end # Calculates hash code according to all attributes. # @return [Fixnum] Hash code def hash [id, account_id, sale_id, delivery_id, detail_ids, name, furigana, postal, pref_id, pref_name, address1, address2, tel, preferred_date, preferred_period, slip_number, noshi_text, noshi_charge, card_name, card_text, card_charge, wrapping_name, wrapping_charge, delivery_charge, total_charge, memo, delivered].hash end # Builds the object from hash # @param [Hash] attributes Model attributes in the form of hash # @return [Object] Returns the model itself def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the the attribute # is documented as an array but the input is not if attributes[self.class.attribute_map[key]].is_a?(Array) self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) end elsif !attributes[self.class.attribute_map[key]].nil? self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) end # or else data not found in attributes(hash), not an issue as the data can be optional end self end # Deserializes the data based on type # @param string type Data type # @param string value Value to be deserialized # @return [Object] Deserialized data def _deserialize(type, value) case type.to_sym when :DateTime DateTime.parse(value) when :Date Date.parse(value) when :String value.to_s when :Integer value.to_i when :Float value.to_f when :BOOLEAN if value.to_s =~ /\A(true|t|yes|y|1)\z/i true else false end when :Object # generic object (usually a Hash), return directly value when /\AArray<(?.+)>\z/ inner_type = Regexp.last_match[:inner_type] value.map { |v| _deserialize(inner_type, v) } when /\AHash<(?.+?), (?.+)>\z/ k_type = Regexp.last_match[:k_type] v_type = Regexp.last_match[:v_type] {}.tap do |hash| value.each do |k, v| hash[_deserialize(k_type, k)] = _deserialize(v_type, v) end end else # model temp_model = ColorMeShop.const_get(type).new temp_model.build_from_hash(value) end end # Returns the string representation of the object # @return [String] String presentation of the object def to_s to_hash.to_s end # to_body is an alias to to_hash (backward compatibility) # @return [Hash] Returns the object in the form of hash def to_body to_hash end # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash hash = {} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) next if value.nil? hash[param] = _to_hash(value) end hash end # Outputs non-array value in the form of hash # For object, use to_hash. Otherwise, just return the value # @param [Object] value Any valid value # @return [Hash] Returns the value in the form of hash def _to_hash(value) if value.is_a?(Array) value.compact.map { |v| _to_hash(v) } elsif value.is_a?(Hash) {}.tap do |hash| value.each { |k, v| hash[k] = _to_hash(v) } end elsif value.respond_to? :to_hash value.to_hash else value end end end end