According to https://dev.bitly.com/link_metrics.html#v3_link_clicks,
we can send multiple parameters like link, unit, etc.
Here i am using this gem https://github.com/philnash/bitly
i am actually looking for Clicks by Day,
i tried
Bitly.client.clicks("bitly_short_url").clicks_by_day, works fine
but i need to change Time Zone value
i tried this
Bitly.client.info({"link" =>"bitly_short_url", "timezone" => -6}).clicks_by_day
and i am getting error.
Is there any other way to get result for different timezone?
Please help
Try this,
Bitly.client.clicks({"link" =>"bitly_short_url", "timezone" => -6}).clicks_by_day
info API doesn't take link or timezone as parameters. But, clicks API takes that. You are passing parameters of clicks API to info API. That is the reason you are getting errors.
Related
I want to fetch the call logs for the last 5 days, I read on the documentation
You can also specify an inequality, such as EndTime<=YYYY-MM-DD, to read calls that ended on or before midnight of this date
I am trying the following with no luck
#client.calls.list(to: phone_number, end_time: ">=#{Time.now - 5.days}")
Twilio developer evangelist here.
There are several things here, and I need to apologise for at least one of them.
Firstly, the less than/greater than equal that the Twilio API implemented was actually a bit of a hack with the way the parameters are formatted. The parameter as the docs point out is EndTime<=YYYY-MM-DD but this is made of the parameter name EndTime< and the parameter value YYYY-MM-DD separated by =. I apologise that this seemed like a cool hack but actually made things harder.
The Ruby library actually tries to unpick this and make it more sensible again. You can use the parameter end_time_after instead of trying to form the correct end_time format.
Second, I ran the string you were using for the end_time and it produced this:
irb(main):001:0> ">=#{Time.now - 5.days}"
=> ">=2021-02-28 14:35:44 +1100"
So when a time is stringified in Ruby, it doesn't just show up in the YYYY-MM-DD format.
So, to fix your API call, should format the date to YYYY-MM-DD and use end_time_after. Note, since you're using ActiveSupport, you can also call on 5.days.ago instead of Time.now - 5.days.
This should work for you:
#client.calls.list(to: phone_number, end_time_after: "#{5.days.ago.strftime("%Y-%m-%d")}")
Let me know if this helps at all.
I'm using Ruby on Rails and I'm implementing a library called stock_quote. Using its Github Documentation
I've been able to succesfully use the library, using different methods in RoR, like:
StockQuote::Stock.quote
StockQuote::Stock.stats
StockQuote::Stock.chart
But I'm having issues to fetch an specific date. For example, I can fetch the last six months in a daily basis, using:
#stock_chart = StockQuote::Stock.chart(params[:id], '6m')
But I need to fetch an specific date with this method. In the iextrading documentation, it says:
"Specific date : IEX-only data by minute for a specified date in the format YYYYMMDD if available. Currently supporting trailing 30 calendar days''
And the HTTP requested is:
/stock/aapl/chart/date/20180620
HTTP request highlighted - for specific date
I tried to execute this commend in Ruby On Rails, but I haven't been able to translate the HTTP request into a proper RoR format in order to succesfully fetch the trend data. In the stock_quote documentation there is not also any reference to this specific command.
I appreciate any help with this issue, I've tried around 20+ syntax ways but they didn't work.
I have a datetime value which comes from the API in this format: 2015-07-07T17:30:00+00:00. I simply want to split it up between the date and time values at this point. I am not using an Active Record model and I prefer not to use an sql database if I can.
The way I have set up the app means that the value is "stored" like this in my view: #search.dining_date_and_time
I have tried two approaches to solving this problem:
Manually based on this previous stackoverflow question from 2012: Using multiple input fields for one attribute - but the error I get is the attribute is "nil" even though I put a "try"
Using this gem, https://github.com/ccallebs/split_date_time which is a bit more recent and seems to be a more elegant solution, but after closely following the doc, I get this error, saying my Search model is not initalized and there is no method: undefined method dining_date' for #<Search not initialized>
This is when instead I put #search.dining_date in the view, which seems to be the equivalent of the doc's example (its not that clear). The doc also says the method will be automatically generated.
Do I need to alter my model so I receive the data from the API in another way? ie. not get the variable back as #search.dining_date_and_time from the Search model for any of this to work?
Do I need an Active Record model so that before_filter or before_save logic works - so i can (re)concatenate after splitting so the data is sent back to the API in a format it understands. Can I avoid this - it seems a bit of overkill to restructure the whole app and put in a full database just so I can split and join date/time as needed.
Happy to provide further details, code snippets if required.
As I am not using a conventional Rails DB like MySql Lite or Postgresql, I found that the best solution to the problem was by using this jQuery date Format plugin: https://github.com/phstc/jquery-dateFormat to split the date and time values for display when I get the data back from the API.
The Github docs were not too expansive, but once I put the simply put the library file in my Rails javascript assets folder, I just had to write a few lines of jQuery to get the result and format I wanted:
$(function() {
var rawDateTime = $('#searchDiningDateTime').html();
// console.log(rawDateTime);
var cleanDate = $.format.date(rawDateTime, "ddd, dd/MM/yyyy");
// console.log(cleanDate);
$('#searchDiningDateTime').html(cleanDate);
var cleanTime = $.format.date(rawDateTime, "HH:mm");
// console.log(cleanTime);
$('#searchTime').html(cleanTime);
});
Next challenge: rejoin the values on submit, so the API can read the data by sending/receiving a valid request/response. (The values can't be split like this when sent to the remote service).
Problem
Using the Twilio REST API, I want to request only messages that I haven't downloaded yet. It seems the cleanest way to do this would be to download only messages after a specified SID.
Information not in the docs
The Twilio filter docs don't have this option. They only describe to, from, and date_sent.
However, it appears that Twilio does have this feature. You can see in their paging information, that the the nextpageuri contains AfterSid.
When browing the website, the URL contains /user/account/log/messages?after=SMXXXXXX
What I've tried so far
Using the twilio-ruby client, I have tried the following without success:
list = #client.account.sms.messages.list({after: 'SMXXXXXX'})
list = #client.account.sms.messages.list({AfterSid: 'SMXXXXXX'})
list = #client.account.sms.messages.list({after_sid: 'SMXXXXXX'})
From Dan Markiewicz - Twilio Customer Support
Unfortunately, we do not support filtering by this field in our API at this time. Your best option would be to get the DateCreated info on the SID you want to filter by and then use that to filter the messages by only those sent after that date. Since the date filter only supports filtering down to the day, it may return some number of unwanted messages that were sent that day but before the message you want to filter by. However, each message in the list will have a full date_created field down to the second, so you should be able to filter these out fairly easily on your end. This should produce the result you need.
After looking at the documentation you outlined, it looks like what you want to accomplish can't be done by the twilio-ruby gem. This link shows which filters are supported by the list method inside the gem in regards to messages.
If you look at the source here, starting on line 45 the gem uses next_page_uri as a way of determining the offset of where the next page should begin. For instance:
calls = twilio_client.account.calls.list # returns the initial set of calls.
calls.next_page # this uses next_page_uri to return the next set of calls internally.
This isn't something that can be changed via the gem currently.
It seems a little odd to my, but although everybody knows about the new google search urls (see Google using # instead of search? in URL. Why?) no one has a problem with the HTTP_REFERER.
I'm using the referrer to parse the google string for the searchquery (&q= ) but as this is all in a hash-tag it wont be sent to the server and all i get is "http://www.google.de/".
So do you know a way of getting the query the user searched for, befor landing on my site?
Due to late-2011 Google security changes, this is no longer possible when the search was performed by a signed-in Google user. See:
http://googleblog.blogspot.com/2011/10/making-search-more-secure.html
http://analytics.blogspot.com/2011/10/making-search-more-secure-accessing.html
Since there are multiple q's in the query string you have to match the "q" parameter globally and take the last one:
/[?|&|#]q=([^&|^#]+)/ig
Get rid of "site:" searches (there are others, but I haven't done them)
/[\+|?|&]?site:([^&|^#])+/g, '');
Then parse the results.
/[\w^'\(\)\{\}]+|"[^"]+"/g
This has been working well for me.