jeudi 8 octobre 2020

Savon::SOAPFault: (s:Client) Element 'RequestContext' is missing from the header

I am using savon gem in rails to call purolator E-Ship soap APIs,

gem 'savon', version 2.12.0

Here is my code sample where I am calling the actual API

@client = Savon.client(wsdl: "#{Rails.root.to_s}/app/carriers/wsdls/purolator/tracking_service/TrackingServiceDev.wsdl",
              "soap_header" => {
                "RequestContext" => {
                  "Version" => '1.2',
                  "Language" => 'en_US',
                  "GroupID" => 'xxx',
                  "RequestReference" => 'Rating Example'
                }
              },
              :basic_auth => ["xxxxxxxxxx", "xxxxxxxxx"], 
              :log => true, :pretty_print_xml => true, :element_form_default => :unqualified)
body = {
      "PIN" => {
        "Value" => 329014521622
      }
    }
@client.call(:get_delivery_details, message: body).body

Here is the Request XML that is being generated and displayed by Savon

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:q12="http://purolator.com/pws/service/v1" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://purolator.com/pws/datatypes/v1" xmlns:ins1="http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation" xmlns:ins2="http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF">
  <env:Header>
    <RequestContext>
      <Version>1.2</Version>
      <Language>en_US</Language>
      <GroupID>xxx</GroupID>
      <RequestReference>Rating Example</RequestReference>
    </RequestContext>
  </env:Header>
  <env:Body>
    <q12:GetDeliveryDetailsRequest>
      <PIN>
        <Value>329014521622</Value>
      </PIN>
    </q12:GetDeliveryDetailsRequest>
  </env:Body>
</env:Envelope>

and here is the response I am getting back from the API

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode>s:Client</faultcode>
      <faultstring xml:lang="en-CA">Element 'RequestContext' is missing from the header</faultstring>
    </s:Fault>
  </s:Body>
</s:Envelope>

API is throwing an error message that Element 'RequestContext' is missing from the header but I provided this header and it is displayed in request as well. Can anyone please point me in the right direction and let me know what I am missing here.

mercredi 7 octobre 2020

How to import from JS and not put in the script

I implemented these 4 scripts in my head in ruby ​​on rails:

<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.7/ScrollMagic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.7/plugins/animation.gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.7/plugins/debug.addIndicators.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.0.1/dist/gsap.min.js"></script>

So, ScroolMagic, animation gsap, debug indicators and gspa. But in Ruby on Rails it's better to create a separated folder/file to protect and seperate your js code.

So for gsap it's ok. I did this inside my js.file in my javascript folder:

    import { gsap } from "gsap";

But for the 2 others (debug.addIndicators is not a priority) i don't know how to do, i tried a lots of possibilities like:

 import { ScrollMagicPluginGsap } from "scrollmagic-plugin-gsap";
    import ScrollMagic from 'ScrollMagic';
    import * as ScrollMagic from 'ScrollMagic';

and more... can someone help me please?

No method error undefined method `each' in ruby

i try to write a function get meeting details from table online meeting rooms i specific 3 parameter: start_date & end_date & username this function should return api in formate : details[Name] = ... & details[...] = ... as following in code In database we have multiple colon and data i want only name and sheduled_on and condition between 2 date as parameter I dont understand what is the error in my code ?

Error :

hh
2
1
[FedenaRescue] No method error undefined method `each' for #<BbbMeetingRoom:0x7fd0261d3be0>

NoMethodError (undefined method `each' for #<BbbMeetingRoom:0x7fd0261d3be0>):
  vendor/plugins/madrasatie_api/app/controllers/api/meetingapi_controller.rb:35:in `get_meeting'
  passenger (4.0.59) lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
  passenger (4.0.59) lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
  passenger (4.0.59) lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
  passenger (4.0.59) lib/phusion_passenger/request_handler.rb:455:in `start_threads'
  passenger (4.0.59) lib/phusion_passenger/request_handler.rb:449:in `initialize'
  passenger (4.0.59) lib/phusion_passenger/request_handler.rb:449:in `new'
  passenger (4.0.59) lib/phusion_passenger/request_handler.rb:449:in `start_threads'
  passenger (4.0.59) lib/phusion_passenger/request_handler.rb:448:in `times'
  passenger (4.0.59) lib/phusion_passenger/request_handler.rb:448:in `start_threads'
  passenger (4.0.59) lib/phusion_passenger/request_handler.rb:447:in `synchronize'
  passenger (4.0.59) lib/phusion_passenger/request_handler.rb:447:in `start_threads'
  passenger (4.0.59) lib/phusion_passenger/request_handler.rb:208:in `main_loop'
  passenger (4.0.59) helper-scripts/rack-preloader.rb:161

Rendering single_access_tokens/500.xml

My Code :

class Api::MeetingapiController < ApiController
  require 'net/http'
  require 'json'
  require 'net/https'
  require 'securerandom'
  
  helper_method :https
 
  def get_meeting
    logger.info "hh"
    @start_date = params[:start_date].present? ? params[:start_date].to_date : @local_tzone_time.to_date
    @end_date = params[:end_date].present? ? params[:end_date].to_date : (@local_tzone_time).to_date
    @user = User.active.first(:conditions => ["username LIKE BINARY(?)",params[:username]])
    @details = []
    if @user.admin?
      @rooms = OnlineMeetingRoom.find_all_by_date(:conditions=>"( Date(scheduled_on) between '#{@start_date}' and '#{@end_date}' or Date(scheduled_on) = '#{@start_date}' or Date(scheduled_on) = '#{@end_date}' )",:order=>"id DESC")
      logger.info "2"
      else
    logger.info "here1"
    @rooms = OnlineMeetingRoom.valid_meetings
    logger.info "here2"
    @rooms = @rooms.rooms_for_user(@user)  unless @user.admin? 
    logger.info "here3"
    @rooms = @rooms.scheduled_on_gte(@start_date).scheduled_on_lte(@end_date.end_of_day)
    logger.info "here4"
      end
    
    logger.info "1"
       
    @rooms.each do |r|
    room = Hach.new
    logger.info "555"
    room["Name"] = r.name
    logger.info "666"
    room["Created_by"] = @user
    logger.info "999"
    room["Shedule on"] = r.sheduled_on
    logger.info "000"
    @details << room
  end
  respond_to do |format|
        format.json {render :json=>{ :data => {:details =>JSON.parse(@details.to_json.gsub("'", %q(\\\')))}, :statusCode => 200, :statusMessage => "OK" }}

     end
  end
  end 
 

mardi 6 octobre 2020

Problem with nio4r gem: An error occurred while installing nio4r (1.2.1), and Bundler cannot continue

Hi everyone I have just started using ruby ​​on rails I have a problem when I go to effect "bundle update" gives me this error:

"An error occurred while installing nio4r (1.2.1), and Bundler cannot continue. Make sure that gem install nio4r -v '1.2.1' succeeds before bundling. "In Gemfile: devise_token_auth was resolved to 0.1.40, which depends on rails was resolved to 5.0.0, which depends on actioncable was resolved to 5.0.0, which depends on nio4r

Ruby version:2.3.0

I tried to run various commands like:

bundle config build.nio4r --with-cflags="-std=c99" brew update

but they didn't work

How to retain PORO Form object field inputs?

I've created a R-o-R Form object which takes in attributes and then saves those attributes to some nested objects, however, upon failing the validations, the input values disappear. Is there anyway to retain them?

class FormObject
 include ActiveModel::Model
 attr_accessor(:name, :date)
 
 def initialize(params = {})
  @params = params
 end

 def save
  return if invalid?
  no = NestedObject.new(nested_object_params)
  no.save
 end

 def nested_object_params
  @params.permit(:name, :date)
 end
end

and this is the controller

class Controller
 def new
  @form = FormObject.new
 end

 def create
  @form = FormObject.new(form_object_params)
  if @form.save
    redirect_to ...
  else
    render :new
  end
 end

 def form_object_params
  params.require(:form_object).permit(:name, :date)
 end
end

lundi 5 octobre 2020

I am getting an ActiveJob::DeserializationError when trying to attach photo while seeding

I am trying to learn how to use active storage and AWS. I am attempting to give Users the option of having a picture and I managed to make it work within my app, but am stuck when trying to give users in my seed file photos.

Right now some problematic code in my seeds file is:

User.destroy_all

user = User.create!(
    id: "1",
    email: "admin",
    password: "admin1"
)

file = File.open('app/assets/images/robot-avatar.png')
user.photo.attach(io: file, filename: 'robot-avatar.png')

When I run rails db:seed, I'm receiving an error which states:

ActiveJob::DeserializationError: Error while trying to deserialize arguments: Couldn't find ActiveStorage::Blob with 'id'=17

Im still pretty new to coding in general, and extremely new when it comes to Active Storage/AWS, so any help would be appreciated. Thanks

regex input path string [duplicate]

Hey so im new to Regex but what im basically trying to do is have the user input a path and just check if my current string contains any matching paths. So for example

Paths = "/cookie /cookie/iceCream /"
rexexInput = "/coo"

if(paths.match(regexInpute))
  //do something
end

so basiaclly just checking if the user input path is contained within the string