Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 是否有通过Ruby使用LocationLabs或Loc Aid的开源示例?_Ruby On Rails_Ruby_Geolocation_Location Based Service - Fatal编程技术网

Ruby on rails 是否有通过Ruby使用LocationLabs或Loc Aid的开源示例?

Ruby on rails 是否有通过Ruby使用LocationLabs或Loc Aid的开源示例?,ruby-on-rails,ruby,geolocation,location-based-service,Ruby On Rails,Ruby,Geolocation,Location Based Service,和是公开RESTAPI的位置聚合服务。他们目前提供Java、.NET和PHP SDK。API并不复杂,但作为一个学习工具,最好有一个Ruby教程或示例,可以使用,扩展等等。经过进一步分析,我在的基础设施上构建了我的应用程序。因为我能找到的Ruby示例不多,所以我将分享我应用程序中的一个片段 # Get SAVON soap client locaid location services # Parameters: # - none # Returns: SOAP client

和是公开RESTAPI的位置聚合服务。他们目前提供Java、.NET和PHP SDK。API并不复杂,但作为一个学习工具,最好有一个Ruby教程或示例,可以使用,扩展等等。

经过进一步分析,我在的基础设施上构建了我的应用程序。因为我能找到的Ruby示例不多,所以我将分享我应用程序中的一个片段

  # Get SAVON soap client locaid location services
  # Parameters:
  #   - none
  # Returns: SOAP client for locaid location services
  def get_location_client
    Savon::Client.new do
      wsdl.document = LOCAID_CONFIG['use_local_wsdl'] ?
        File.expand_path(LOCAID_CONFIG['get_location_wsdl'].to_s, ::Rails.root.to_s) :
        LOCAID_CONFIG['get_location_wsdl'].to_s
      wsdl.endpoint = LOCAID_CONFIG['get_location_endpoint'].to_s
    end
  end


  # Strip the return result from locaid response as a hash
  # Parameters:
  #   - raw_response: Raw response XMLfrom locaid services
  #   - response_name: Response name which wrap the response return result in locaid response XML
  # Returns: Hash corresponding to the key "return" in locaid soap response hash.
  # Sample Raw Response:
  #   {:subscribe_phone_response=>{:return=>{:error=>{:error_code=>"00001", :error_message=>"Invalid or inactive user"}, :transaction_id=>"14028251"},
  #       :"@xmlns:ns2"=>"http://webservice.portico.locaid.net/"}}
  def strip_locaid_return(raw_response, response_name)
    unless raw_response.to_hash.has_key?(response_name)
      raise TropoExceptions::ExternalError
    end
    raw_response[response_name][:return]
  end

  # Get location from locaid by the caller id
  # Parameters:
  #     - @caller_id: Caller id get from scope value
  # Returns: none
  def location_from_locaid
    client = get_location_client
    client.http.read_timeout = LOCAID_CONFIG['get_location_timeout'].to_i
    # Call locaider service to get location
    response = client.request :wsdl, :get_locations_x do |soap|
      soap.body = {
          :login  => LOCAID_CONFIG['login'],
          :password  => LOCAID_CONFIG['password'],
          :class_id => LOCAID_CONFIG['class_id'],
          :msisdn_list => ["1#{@caller_id}"],
          :coor_type => "DECIMAL",
          :location_method => LOCAID_CONFIG['location_method'],
          :sync_type => "SYN",
          :overage => "1"
      }
    end

    result_hash = strip_locaid_return(response, :get_locations_x_response)
    if result_hash.has_key?(:error)
      raise TropoExceptions::ExternalError
    end

    yield result_hash[:location_response].is_a?(Array) ?
        result_hash[:location_response][0] :
        result_hash[:location_response]

  rescue Savon::Error, Timeout::Error => e
    logger.error e
    yield nil
  end
end

如果没有可用的包装器,请不要忘记使用ActiveResource