In nuSOAP, how to return simple data type having multiple occurance as response? - nusoap

Suppose my response message can be like this
<Response>
<ResponseCode>false</ResponseCode>
<ResponseMessage>reason 1</ResponseMessage>
<ResponseMessage>reason 2</ResponseMessage>
<ResponseMessage>reason 3</ResponseMessage>
</Response>
this (xsd:string) item is having multiple occurance.
How to add and configure this kind of rsponse message in nuSOAP server?
Thanks in advance :)

I found this example on another forum. It helped me solving a similar issue with multiple elements:
<inventory>
<car>
<make>Nissan</make>
<model>Maxima</model>
<year>2005</year>
<quantity>3</quantity>
</car>
<car>
<make>Nissan</make>
<model>Maxima</model>
<year>2006</year>
<quantity>1</quantity>
</car>
</inventory>
NuSOAP takes the approach that "car", which is repeated, is an array, so
the "car" element in the associative array points to a simple array:
$car[] = array('make' => 'Nissan', 'model' => 'Maxima', 'year' => 2005,
'quantity' => 3);
$car[] = array('make' => 'Nissan', 'model' => 'Maxima', 'year' => 2006,
'quantity' => 1);
$inventory = array('car' => $car);

Related

using Foreach to make a table

Im new to PHP and I made this to display to my website what has been uploaded in the fdpp portal
<?php $resp = file_get_contents("http://fdpp.blgs.gov.ph/api/documents?source=datatable&sSearch=kalinga");
$clean = json_decode($resp);
print_r($clean); ?>
this is the result :
stdClass Object
(
[iTotalRecords] => 130035
[iTotalDisplayRecords] => 879
[sEcho] => 0
[aaData] => Array
(
[0] => stdClass Object
(
[lgu] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129293'>CAR<br/>Kalinga<br />Balbalan</a>
[document] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129293'>Local Disaster Risk Reduction and Management Fund Utilization (LDRRMF)</a>
[period] => Quarter 1 2014
[status] => Required • SUBMITTED
[desc] => The atng.
)
[1] => stdClass Object
(
[lgu] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129188'>CAR<br/>Kalinga<br />Balbalan</a>
[document] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129188'>Manpower Complement</a>
[period] => Quarter 1 2014
[status] => Required • SUBMITTED
[desc] => The file ag.
)
what shall I add to my code to put this in a table with column name lgu, document, period? I tried reading foreach manual but I cant figure it out can someone help me?
I have to agree with PeeHaa (+1) with not enough information given, but I'm going to attempt to help you out.
The following assumptions were made:
You have a local MySQL DB named "testdb"
You have the PDO extension installed
In "testdb", you have a table named "test_table" with 4
columns (id, lgu, document, period)
First, you need to set the second parameter in json_decode to true to return an associative array rather than an object (PHP: json_decode).
So, based upon the limited information, here is a working version:
<?php
$resp = file_get_contents("http://fdpp.blgs.gov.ph/api/documents?source=datatable&sSearch=kalinga");
$clean = json_decode($resp,true);
// Open connection to your MySQL DB
$db = new PDO('mysql:host=localhost;dbname=testdb', 'username', 'password');
// Parse the now-associative array and insert into table
foreach($clean['aaData'] as $doc){
$stmt = $db->prepare("INSERT INTO test_table(lgu,document,period) VALUES(:lgu,:document,:period)");
$stmt->execute(array(':lgu' => $doc['lgu'], ':document' => $doc['document'], ':period' => $doc['period']));
}
?>
You should really provide some more information for a more exact answer.
But, this should set you in the right direction.

How do you use the Gibbon Gem to automatically add subscribers to specific interest groups in MailChimp?

I'm trying to figure out how I can use the Gibbon gem in Rails to automatically add subscribers to specific interest groups in MailChimp?
I've found this article which details a non-Rails method for doing so: http://roman.tao.at/uncategorized/mailchimp-api-listsubscribe-listbatchsubscribe-and-groups/
I'd like to figure out how to implement that functionality using the Gibbon gem: https://github.com/amro/gibbon
FYI, I'm also a novice with both MailChimp and Rails.
Finally, after hours of perusing through code. I've found the example I'm looking for!
Thanks to TJ Moretto for providing this on a Google Groups thread:
I'm using the gibbon gem, but ran into the same types of issues.
Here's how I had to format the parameters to finally get this to work:
gb.list_subscribe({:id => "#{list.id}",
:email_address => user.email,
:update_existing => true,
:double_optin => false,
:send_welcome => false,
:merge_vars => {'FNAME' => "#{user.first_name}",
'LNAME' => "#{user.last_name}",
'GROUPINGS' => {0 => {'id' => grouping.id, 'groups' => "#{challenge.name}"}}}
})
Hope that helps.
Mailchimp Team - based on the number of issues that everyone runs into
when trying to do this (across all programming languages), I suggest
you update the API documentation to be more clear.
Update for version 2.0 of the MailChimp API and version 1.0 of Gibbon (For #Calin and posterity). Here are the necessary changes from the previous version. The API object is accessed like this now:
gb = Gibbon::API.new
And list methods like so:
gb.lists.subscribe(params)
Finally the :email_address parameter has been replaced by the :email parameter, which should be given a value of the following form: The value should itself be a hash with one key, either 'email' or 'leid', and the value should be either the email address of the subscriber or MC's unique identifier (LEID) for the subscriber.
So a full subscription call might look something like this:
gb = Gibbon::API.new
gb.lists.subscribe(:id => "ed6d1dfef4",
:email =>
{ "email" => "example#domain.com" },
:merge_vars =>
{:groupings =>
{
0 => { :id => "95", :groups => ["Some Group", "Another Group"]},
1 => { :id => "34", :groups => ["A Third Group"]}
}
},
:update_existing => "true",
:double_optin => "false",
:replace_interests => "false")

How do I convert an array of strings into a comma-separated string?

I have an array:
array = ["10", "20", "50", "99"]
And I want to convert it into a simple comma-separated string list like this:
"10", "20", "50", "99"
array.join(',') will almost do what you want; it will not retain the quotes around the values nor the spaces after.
For retaining quotes and spaces: array.map{|item| %Q{"#{item}"}}.join(', ')
This will print "\"10\", \"20\", \"50\", \"99\"". The escaped quotes are necessary assuming the question does in fact call for a single string.
Documentation on the %Q: string literals.
You could use inspect as suggested in another answer, I'd say that's personal preference. I wouldn't, go look at the source code for that and choose for yourself.
Useful aside: array.to_sentence will give you a "1, 2, 3 and 4" style output, which can be nice!
["10", "20", "50","99"].map(&:inspect).join(', ') # => '"10", "20", "50", "99"'
Here:
array.map {|str| "\"#{str}\""}.join(',')
Several answers have offered solutions using #map, #inspect, #join. All of them fail to get certain details of CSV encoding correct for edge cases involving embedded commas and/or string delimiters in the elements.
It's probably a better idea to use the stdlib class CSV then to roll your own.
irb> require 'csv'
=> true
irb> a = [10,'1,234','J.R. "Bob" Dobbs',3.14159]
=> [10, "1,234", "J.R. \"Bob\" Dobbs", 3.14159]
irb> puts a.to_csv
10,"1,234","J.R. ""Bob"" Dobbs",3.14159
The map.join solutions are sufficient if this encoding doesn't need to care about embedded delimiters, or is intended for some internal representation only, but they will fail if generating data for exchange with other programs that expect Comma Separated Values (CSV) as a generally understood representation.
The simplest solution is to use the built in ".to_sentence" method.
So
["fred", "john", "amy"].to_sentence outputs "fred, john, and amy"
This is a slightly alternative solution, particularly handy if you need to convert an array with double quoted strings to a single quoted list (for say SQL queries):
"'#{["John Oliver", "Sam Tom"].join("','")}'"
to
'John Oliver', 'Sam Tom'
Attribution: https://alok-anand-ror.blogspot.com/2014/04/ruby-join-array-elements-with-single.html
This is how you can send push notifications using FCM for Android devices.
Assuming you want notify followers when ever a user posts something on their status this is how you do it. This is done in Rails 5.2.6 for Rest Apis--- But still you can use the same for web push notifications. This is for sending to many devices with registration_ids to target followers with notifications.
Gem : fcm
in your controller:
require "fcm"
def create_vibe(user)
#vibe = user.vibes.new(content: #content, picture: #picture, video: #video, isvideofile: #isvideofile, video_thumbnail: #video_thumbnail, source: #source, background_color: #background_color)
#followed = user.followers
if #followed.present?
#registration = #followed.map { |s| s.registration_id }
end
if #vibe.save
fcm = FCM.new("") # set your FCM_SERVER_KEY
options = {
data: {
notification_type: 1,
title: "#{#vibe.user.username} " "has posted a new Vibe",
body: "#{#vibe.content}",
user_data: {
vibe_id: #vibe.id,
user_id: #vibe.user.id,
background_color: #background_color,
},
},
}
response = fcm.send(#registration, options)
puts response
render :status => 200,
:json => { :success => true,
:info => "Vibe posted successfully",
:vibe_info => {
:content => #content,
:picture => #picture,
:video => #video,
:video_thumbnail => #video_thumbnail,
:isvideofile => #isvideofile,
:source => #source,
:fcm => options,
} }
else
render :status => 200, :json => { :success => false, :result => "Vibe can't be blank" }
end
end

How to format scientific data into proper data series for graph display in Ruby (Rails 3.1.x)?

Needing some guidance about how to properly graph data that is very small and stored as BigDecimal.
If anyone has had experience using BigDecimals in any graphing scenario I believe your input on how you placed these into a usable sequence would be invaluable.
Presently I'm using lazy_high_charts and it really seems that this is going to work out exceptionally well, however I've run into a hitch where I've not dealt with data on the minute BigDecimal scale hitherto.
Given my queries, I'll be pulling out about a 1,000 data points for a few different series of data ranging in accuracy from about 0.100E-9 to about 0.100E-1.
What would be the best way to prep these data series for presentation in such a graph that has a scientific application and therefore precision is important? I'm not sure if I could or should continue in BigDecimal or something else?
I'm presently querying the database with a line similar to:
series_a = dataset.order("date").select('data_set.data1').limit(1000).all.zip
I'd appreciate some guidance of going from this result (again, the output is an array of BigDecimals) to the appropriate format for what will go into the chart series.
An contextual example of the code I'm using to build the chart in my controller is:
#h = LazyHighCharts::HighChart.new('graph') do |f|
series_a = dataset.order("date").select('data_set.data1').limit(1000).all.zip
series_b = dataset.order("date").select('data_set.data3').limit(1000).all.zip
f.series(:name => 'Data 1', :data => series_a)
f.series(:name => 'Data 2', :data => series_b)
f.chart({:defaultSeriesType => "line" })
f.yAxis [
{:title => { :text => "Left Y Label", :margin => 10} },
{:title => { :text => "Right Y Label"}, :opposite => true }
]
f.xAxis(:title => { :text => "X Label"} )
f.title(:text => "Graph Title")
f.legend(:align => 'right', :verticalAlign => 'top', :y => 75, :x => -50, :layout => 'vertical')
end
I think I'm a bit further along in my understanding of this having decided to convert the BigDecimals to strings as per "How to access fields by attribute name from ActiveRecord row results?" However it appears ultimately this fails and gives erratic results as the series functions :data field expects, I think, numeric input. I am thinking that this ultimately emits json to highcharts, however I'm still stuck for the moment in my attempt to pass these values on in correctly.
When you do this:
series_a = dataset.order("date").select('data_set.data1').limit(1000).all.zip
you'll end up with an array of arrays as we already discussed elsewhere. If you get rid of the zip, you should end up with an array of objects in series_a. I'd guess that chart would be happier with an array of numbers so:
series_a = dataset.order("date").
select('data_set.data1').
limit(1000).
all.
map(&:data1)
or, if data1 is a BigDecimal (due to using a fixed precision type in the database) then maybe you'd want this:
series_a = dataset.order("date").
select('data_set.data1').
limit(1000).
all.
map { |o| o.data1.to_f }
to get an array of floating point values that the chart should know what to do with.
I'm not familiar with Highcharts so there is some guesswork here.

In Symfony how to set default values to sfWidgetFormDateRange from action

In Symfony how to set default values to sfWidgetFormDateRange from action
Basically you have to do the following:
$form->setDefault('field_name', array('from' => 'yesterday', 'to' => '+10 years'))
These yesterday and +10 years chants actually are anything suitable for strtotime function. Also, you could pass explicit dates without casting any magic:
$form->setDefault('field_name', array('from' => array('month' => 10, 'day' => 12, 'year' => 1984), 'to' => '+10 years'))

Resources