The following method
now = Date.today
#start_week = Date.commercial(now.cwyear,now.cweek+9)
is returning and argument error invalid date. This was working under ruby 1.9.3. Oddly enough, there are no complaints regarding
#start_week = Date.commercial(now.cwyear,now.cweek+8)
and the console returns Mon, 28 Dec 2015
So the issue is how does one concisely rollover the year in such a context.
Silly. Transform the method to a succinct
#start_week = Date.today.beginning_of_week + 9.weeks
[get percolator running]
Related
The time is given in this format t=2015-10-01 23:10:11. I tried using the following code, but it throws an error: Time.parse(t).to_i. So, how do I convert it?
Your code works. You forgot require 'time'
require 'time'
t="2015-10-01 23:10:11"
Time.parse(t).to_i
# => 1443766211
By the way, please always post the error. Otherwise we have to guess what the problem is.
Wrap your t as a String
t='2015-10-01 23:10:11'
Now you can both
DateTime.parse t
=> Thu, 01 Oct 2015 23:10:11 +0000
and
Time.parse t
=> 2015-10-01 23:10:11 +0100
and than call .to_i on any of it:
Time.parse(t).to_i or DateTime.parse(t).to_i
Time.parse('t=2015-10-01 23:10:11'.split('=').last).to_i
To illustrate my problem, I made a condensed example from the Apiary.io blueprint tutorial.
FORMAT: 1A
# Gist Fox API
# Group Gist
Gist-related resources of *Gist Fox API*.
## Gists Collection [/gists{?since}]
### List All Gists [GET]
+ Parameters
+ since (optional, string) ... Timestamp in ISO 8601 format: `YYYY-MM-DDTHH:MM:SSZ` Only gists updated at or after this time are returned.
+ Response 200
{
items: []
}
### Create a Gist [POST]
To create a new Gist simply provide a JSON hash of the *description* and *content* attributes for the new Gist.
+ Request (application/json)
{
"description": "Description of Gist",
"content": "String content"
}
+ Response 201
{
}
Then in my apiary documentation I get the following:
GET /gists{?since}
POST /gists{?since}
However, for me it makes sense to have the since query parameter only for the GET request. Unfortunately I didn't find a way to achieve this result:
GET /gists{?since}
POST /gists
Is it something possible?
Update
(Thursday, 23 Oct 2014)
The fix has been deployed; could you please give it a try and let me know if everything works as expected?
The bad news
It is our (Apiary) bug and you're not doing anything wrong :-(
The good news
It is a known bug we are currently working on and it is going to be fixed with the end of this week (Sunday, 19 Oct 2014) :-)
I am using "dropbox-sdk" gem to upload the files in DropBox account. I used the following method to search.
require "dropbox_sdk"
client = DropboxClient.new("ACCESS_TOKEN")
client.search("/", "myfile.ipa")
=> [{"rev"=>"86009",
"thumb_exists"=>false,
"path"=>"/App/myfile.ipa",
"is_dir"=>false,
"client_mtime"=>"Mon, 08 Sep 2014 18:59:17 +0000",
"icon"=>"page_white",
"bytes"=>5050139,
"modified"=>"Tue, 09 Sep 2014 17:55:05 +0000",
"size"=>"4.8 MB",
"root"=>"dropbox",
"mime_type"=>"application/octet-stream",
"revision"=>79144}]
client.search("/", "myfile.ipa")
=> []
i was able to get the response at first time. If i again search with the same file name, it returns with the empty response.
Any idea?
I'm trying to convert the following string to either a hash or json.
How do I do this in ruby?
[{"place":null,"coordinates":null,"in_reply_to_user_id":null,"in_reply_to_status_id":null,
"favorited":false,"truncated":false,"created_at":"Wed Nov 16 08:00:46 +0000 2011","retweet_count":0,"in_reply_to_screen_name":null,
"user":{"profile_background_image_url":"http:\/\/a1.twimg.com\/profile_background_images\/190989640\/afcx.jpg","protected":false,
"statuses_count":23414,"profile_link_color":"FF0000"},"retweeted":false,"in_reply_to_status_id_str":null,"in_reply_to_user_id_str":null,"contributors":null,"geo":null}]
I'm running ruby1.8.7.
What you have appears to be JSON already, so I assume you're looking to get a Ruby Hash from it. If so, then this should work:
Get a JSON library, I used gem install json_pure, which is a native Ruby implementation (there's a faster, C-based version but you wouldn't notice the difference unless your JSON strings are very large or you have a lot of them).
then
require 'json'
arr = JSON(your_json_string_here)
Note that the string you gave is a single-element array containing something that will map to a Ruby Hash. If you just want the hash:
the_hash = arr[0] # or maybe arr.first
I get this:
{"coordinates"=>nil, "created_at"=>"Wed Nov 16 08:00:46 +0000 2011",
"truncated"=>false, "favorited"=>false, "in_reply_to_user_id_str"=>nil,
"contributors"=>nil, in_reply_to_status_id_str"=>nil, "retweet_count"=>0,
"geo"=>nil, "retweeted"=>false, "in_reply_to_user_id"=>nil,
"user"=>{"profile_link_color"=>"FF0000", "protected"=>false,
"statuses_count"=>23414,
"profile_background_image_url"=>"http://a1.twimg.com/profile_background_images/190989640/afcx.jpg"},
"in_reply_to_screen_name"=>nil, place"=>nil, "in_reply_to_status_id"=>nil}
I am trying to implement the youtube_it youtube api wrapper for ruby and have it working except I'm stumped as to how the query results should be accessed.
Here is my query:
client.videos_by(:query => "penguin", :max_results => 1)
Submitting request [url=http://gdata.youtube.com/feeds/api/videos?max-results=1&start-index=1&vq=penguin].
=> #<YouTubeIt::Response::VideoSearch:0xb6c41b14 #feed_id="http://gdata.youtube.com/feeds/api/videos", #updated_at=Wed Nov 03 18:01:39 UTC 2010, #videos=[#<YouTubeIt::Model::Video:0xb6c424d8 #thumbnails=[#<YouTubeIt::Model::Thumbnail:0xb6c6b694 #url="http://i.ytimg.com/vi/oSbLpQEZP1Y/2.jpg", #width=120, #height=90, #time="00:01:34">, #<YouTubeIt::Model::Thumbnail:0xb6c6b248 #url="http://i.ytimg.com/vi/oSbLpQEZP1Y/1.jpg", #width=120, #height=90, #time="00:00:47">, #<YouTubeIt::Model::Thumbnail:0xb6c6a988 #url="http://i.ytimg.com/vi/oSbLpQEZP1Y/3.jpg", #width=120, #height=90, #time="00:02:21">, #<YouTubeIt::Model::Thumbnail:0xb6c69e34 #url="http://i.ytimg.com/vi/oSbLpQEZP1Y/0.jpg", #width=320, #height=240, #time="00:01:34">], #categories=[#<YouTubeIt::Model::Category:0xb6ca5d6c #term="Music", #label="Music">], #noembed=false, #racy=false, #favorite_count=7862, #duration=188, #author=#<YouTubeIt::Model::Author:0xb6c9942c #name="wili", #uri="http://gdata.youtube.com/feeds/api/users/wili">, #updated_at=Tue Nov 02 08:45:25 UTC 2010, #longitude=nil, #position=nil, #view_count=1682350, #html_content="penguin", #media_content=[#<YouTubeIt::Model::Content:0xb6c770d4 #url="http://www.youtube.com/v/oSbLpQEZP1Y?f=videos&app=youtube_gdata", #duration=188, #format=#<YouTubeIt::Model::Video::Format:0xb656d108 #name=:swf, #format_code=5>, #default=true, #mime_type="application/x-shockwave-flash">, #<YouTubeIt::Model::Content:0xb6c766d4 #url="rtsp://v5.cache3.c.youtube.com/CiILENy73wIaGQlWPxkBpcsmoRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", #duration=188, #format=#<YouTubeIt::Model::Video::Format:0xb656d11c #name=:rtsp, #format_code=1>, #default=false, #mime_type="video/3gpp">, #<YouTubeIt::Model::Content:0xb6c75d38 #url="rtsp://v8.cache3.c.youtube.com/CiILENy73wIaGQlWPxkBpcsmoRMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", #duration=188, #format=#<YouTubeIt::Model::Video::Format:0xb656d0f4 #name=:three_gpp, #format_code=6>, #default=false, #mime_type="video/3gpp">], #description="penguin", #latitude=nil, #title="penguin", #published_at=Mon May 08 18:11:01 UTC 2006, #player_url="http://www.youtube.com/watch?v=oSbLpQEZP1Y&feature=youtube_gdata_player", #rating=#<YouTubeIt::Model::Rating:0xb6c5eb4c #min=1, #max=5, #average=4.676985, #rater_count=2746>, #keywords=["pigloo", "penguin"], #video_id="http://gdata.youtube.com/feeds/api/videos/oSbLpQEZP1Y", #where=nil>], #total_result_count=291282, #offset=1, #max_result_count=1>
I would like to retrieve the URL and thumbnail links. Any ideas?
I don't have a great deal of knowledge of this particular gem, but your answer should at least be close to this. You can access the object directly through the videos accessor, which will give you the video object, on which thumbnails each have a url. so you could do the following:
reply = client.videos_by(:query => "penguin", :max_results => 1)
reply.videos.first.thumbnails.first.url # the thumbnail for the first video
reply.videos.first.player_url # The website for the video
reply.videos.first.media_content.first.url # direct embed url
It might be useful to search for some ruby beginners guides to help catch you up to speed as well. Good luck!
william's answer is correct, when you do it
client.videos_by(:query => "penguin", :max_results => 1)
this return an array called videos, so you just need iterate it
client.videos.each do |video|
video.title
video.thumbnails
video.video_id
end
good luck!