Class: Sap::User

Inherits:
SapAnywhereInterface show all
Defined in:
lib/resource/sap/user.rb

Instance Method Summary collapse

Methods inherited from SapAnywhereInterface

#check_access_token, #check_function_and_shop, #convert_payment_type, #convert_price_unit, #delete, #get, #get_access_token, #get_access_token_url, #handle_response, #patch, #post

Constructor Details

#initialize(source) ⇒ User

Note:

对象初始化方法(初始化来源)

对象初始化方法(初始化来源)

Parameters:

  • source (string)


9
10
11
# File 'lib/resource/sap/user.rb', line 9

def initialize(source)
  @source = source
end

Instance Method Details

#find(id) ⇒ Object

Note:

通过接口获得单个数据

通过接口获得单个数据

Parameters:

  • id (Integer)

    数据id



24
25
26
# File 'lib/resource/sap/user.rb', line 24

def find(id)
  get(query(id))
end

#listObject

Note:

通过接口获得一堆数据

通过接口获得一堆数据

Parameters:

  • source (string)

    来源

  • request_name (string)

    请求资源名



17
18
19
# File 'lib/resource/sap/user.rb', line 17

def list
  get(query)
end

#query(params = {}, id = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/resource/sap/user.rb', line 34

def  query(params = {}, id = {})
  # Rails.logger.info params[:user_id]
  request_names = if params.class == Fixnum || params.class == String
                    "#{request_name}/#{params}?expand=*&"
                  elsif id.class == Fixnum
                    "#{request_name}/#{id}?expand=*&"
                  else
                    "#{request_name}?expand=*&"
                  end
  post_params = {
      source: @source,
      request_name: request_names
  }
  # p "params是#{params}"
  # p "id是#{id}"
  # if params.class != Fixnum && params.class != String && params.present?
  #   p " dasdaada"
  #   post_params.merge!(customer: convert_to_sap_customer(params))
  #   p "post_params#{post_params}"
  # end
  # Rails.logger.info "++++++++#{convert_to_sap_order(params)}"
  # if params[:user_id].present?
  #   post_params.merge!(order: convert_to_sap_order(params))
  #   Rails.logger.info "post_params#{post_params}"
  # end
  # p "++---+++#{}"
  post_params.merge(id: id) if id.class == Fixnum
  # p "当前参数#{post_params}"
  post_params
end

#request_nameObject

Note:

获取请求路径的请求名

获取请求路径的请求名



30
31
32
# File 'lib/resource/sap/user.rb', line 30

def request_name
  'Users'
end