duh. I figured it out, I need to make the fields value a JSON object
instead of JSON string.  The code below seems to work and I'm off to
the races, thanks for the help.

    param = {}
    param['a'] = 'b'
    payload = {}
    payload['pdef_url'] = "public/defs/sequence1.rb"
    payload['fields'] = JSON.parse param.to_json

On Mar 9, 6:32 pm, kiko <[email protected]> wrote:
> It seems like I'm so close but then have more issues.  This time it's
> with the quotes being escaped before sending the request.
>
> if you try the above example with RestClient but instead create the
> payload using hashes converted to json it get some weird errors.  For
> example:
>
>     param = {}
>     param['a'] = 'b'
>     payload = {}
>     payload['pdef_url'] = "public/defs/sequence1.rb"
>     payload['fields'] = param.to_json
>
> #then
>
> p RestClient.post(
>   'http://admin:ad...@localhost:3000/processes',
>   payload.to_json,
>   :content_type => 'application/json',
>   :accept => 'application/json')
>
> produces
> Processing ProcessesController#create (for 127.0.0.1 at 2009-03-09
> 17:56:02) [POST]
>   Parameters: {"fields"=>"{\"a\":\"b\"}", "pdef_url"=>"public/defs/
> sequence1.rb"}
>   User Load (1.1ms)   SELECT * FROM "users" WHERE ("users"."login" =
> E'admin') LIMIT 1
>   SQL (0.2ms)   SET client_min_messages TO 'panic'
>   SQL (0.1ms)   SET client_min_messages TO 'notice'
>   SQL (0.1ms)   BEGIN
>   SQL (2.1ms)   INSERT INTO "history" ("created_at", "participant",
> "wfid", "wfrevision", "event", "wfname", "source", "message", "fei")
> VALUES('2009-03-10 00:56:02.911400', NULL, E'20090310-bekobiyudo',
> E'1', E'launch', E'Sequence', E'expool', E'', E'(fei 0.9.20 engine
> public/defs/sequence1.rb Sequence 1 20090310-bekobiyudo process-
> definition 0)') RETURNING "id"
>   SQL (25.8ms)   COMMIT
>   SQL (0.2ms)   BEGIN
>   SQL (0.9ms)   INSERT INTO "process_errors" ("created_at", "wfid",
> "expid", "svalue") VALUES('2009-03-10 00:56:03.032256', E'20090310-
> bekobiyudo', E'0.0', E'--- !ruby/object:OpenWFE::ProcessError
> date: 2009-03-09 17:56:03.032256 -07:00
> error_class: IndexError
> fei: &id001 !ruby/OpenWFE::FlowExpressionId
>  s: (fei 0.9.20 engine public/defs/sequence1.rb Sequence 1 20090310-
> bekobiyudo description 0.0)
> message: :apply
> stacktrace: string not matched
> workitem: !ruby/object:OpenWFE::InFlowWorkItem
>  attributes: "{\\"a\\":\\"b\\"}"
>  flow_expression_id: *id001
>  last_modified:
> ') RETURNING "id"
>   SQL (298.3ms)   COMMIT
>   SQL (0.3ms)   BEGIN
>   SQL (0.6ms)   INSERT INTO "history" ("created_at", "participant",
> "wfid", "wfrevision", "event", "wfname", "source", "message", "fei")
> VALUES('2009-03-10 00:56:03.377025', NULL, E'20090310-bekobiyudo',
> E'1', E'error', E'Sequence', E'expool', E'apply IndexError string not
> matched', E'(fei 0.9.20 engine public/defs/sequence1.rb Sequence 1
> 20090310-bekobiyudo description 0.0)') RETURNING "id"
>   SQL (0.6ms)   COMMIT
>
> I noticed that the difference between the hash built payload and the
> hardcoded one was the Parameters
> hardcoded:
> Parameters: {"fields"=>{"a":"b"}, "pdef_url"=>"public/defs/
> sequence1.rb"}
> hash:
> Parameters: {"fields"=>"{\"a\":\"b\"}", "pdef_url"=>"public/defs/
> sequence1.rb"}
>
> When entered via the hash the fields value is escaped and surrounded
> by quotes.  I thought okay easy fix remove the escape characters
> before posting with the RestClient.  Well I can't figure out how to
> remove the escape characters because they show up in every .to_s I do,
> but then at runtime when I try a gsub it never finds the escape
> character.  When I'm in irb though I can see that the escape character
> doesn't exist viewing the individual characters, it's just when the
> String is printed the escape characters are put in.  I'm wondering
> also if the escape characters are still valid and the workflow engine
> is not processing it correctly.
>
> Sorry if confusing I'm going to play around with it alittle more,
> can't believe how difficult these escape characters have turned out to
> be, I'm also fairly new to ruby so I'll search around and see if
> anyone else has similar issues when trying to print strings or json
> output.
>
> On Mar 2, 5:54 pm, John Mettraux <[email protected]> wrote:
>
> > On Mon, Mar 2, 2009 at 6:50 PM, John Mettraux <[email protected]> wrote:
> > > On Mon, Mar 2, 2009 at 5:26 PM, kiko <[email protected]> wrote:
>
> > >> the form-cli was a hack because the ruote-rest was failing if it was
> > >> other types of content-types so I needed to put some random content-
> > >> type, and the blank pdef argument was required for some reason I never
> > >> figured out.
>
> > >> I made an attempt to launch the process as an httparty client.  Also I
> > >> don't get much of what you mean about your last response, it seems
> > >> your recommending using OpenWFE objects to create the xml or json text
> > >> on the client and send to the server?  My understanding is if you post
> > >> to http:<ruote-web2 server>/processes with parameter pdef_url to the
> > >> process file and parameter fields with a json representation of the
> > >> payload.  My issue is getting the authentication to work.
>
> > > Hello Francisco,
>
> > > I couldn't get Httparty to run with "application/json" for now. But
> > > this shell script works fine :
>
> > > ---8<---
> > > curl \
> > >  --verbose \
> > >  --basic --user "admin:admin" \
> > >  -H "Content-Type: application/json" \
> > >  -H "Accept: application/json" \
> > >  --data '{"pdef_url":"public/defs/sequence1.rb", "fields":{"a":"b"}}' \
> > >  http://localhost:3000/processes
> > > --->8---
>
> > And the "sudo gem install rest-client" equivalent :
>
> > ---8<---
> > require 'rubygems'
> > require 'rest_client'
>
> > p RestClient.post(
> >   'http://admin:ad...@localhost:3000/processes',
> >   '{"pdef_url":"public/defs/sequence1.rb", "fields":{"a":"b"}}',
> >   :content_type => 'application/json',
> >   :accept => 'application/json')
> > --->8---
>
> > Sorry for having wasted your time with httparty.
>
> > Best regards,
>
> > --
> > John Mettraux   -  http://jmettraux.wordpress.com
>
>
--~--~---------~--~----~------------~-------~--~----~
you received this message because you are subscribed to the "ruote users" group.
to post : send email to [email protected]
to unsubscribe : send email to [email protected]
more options : http://groups.google.com/group/openwferu-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to