I'm trying to set a transaction to Universign with the "capsens_universign" gem.
Here's my code to create the transaction:
document_from_content = Universign::Document.new(
name: 'another.pdf',
content: File.open("tmp/test.pdf").read
)
signer = Universign::TransactionSigner.new(
first_name: "Signer's first name",
last_name: "Signer's last name",
email: 'test#gmail.com',
phone_number: 'SOME_PHONE_NUMBER',
success_url: 'https://my_app.com',
signature: Universign::SignatureField.new(coordinate: [37,684], page: 5)
)
transaction = Universign::Transaction.create(
documents: [document_from_content],
signers: [signer],
options: { profile: 'default', final_doc_sent: false, handwritten_signature_mode: 0}
)
I got a code 200 response from this. I can sign the pdf BUT signature stamps are not showing in the PDF generated by Universign when the transaction is completed.
Is it because of this configuration ? Or maybe I didn't understand well the different signatures configurations.
Related
I'm trying to integrate AWS Rekognition into my Rails app. After the user uploads his avatar via Active Storage, Rekognition should show some info about it.
def update
respond_to do |format|
if #user.update(user_params)
if #user.images.attached?
Aws.config.update({
region: 'us-west-2',
credentials: Aws::Credentials.new('ACCESS_KEY', 'SECRET_KEY')
})
rekognition = Aws::Rekognition::Client.new(region: Aws.config[:region], credentials: Aws.config[:credentials])
img = #user.images.first. # original was: File.read(ARGV.first)
#detect faces
resp = rekognition.detect_faces({
image: { bytes: img },
attributes: ["ALL"], # What attributes to return
})
resp.face_details[0].emotions.each do |emo|
puts emo.type + " " + emo.confidence.to_i.to_s #=> Strings "HAPPY", "SAD", "ANGRY"
end
end
end
end
However, I get the error
expected params[:image][:bytes] to be a String or IO object, got value #<ActiveStorage::Attachment id: 4, name: "images", record_type: "User", record_id: 47, blob_id: 9, created_at: ""> (class: ActiveStorage::Attachment) instead.
How can I get the image file property into AWS Rekognition?
There is two way to pass image to Aws::Rekognition.
AWS S3 image url and name
resp = rekognition.detect_faces(
{image:
{s3_object:
{bucket: `bucket name`,
name: `pull path of file`,
},
}, attributes: ['ALL'],
}
)
Via Image object
rekognition.detect_faces({
image: { bytes: File.read(`path of file`) }
})
in your case you are passing ActiveStorage object that can't parse by AWS. that's why it throw error.
I'm developing a learning application for a nonprofit using rails that WILL NOT have access to the internet. All assets must be housed locally. The application contains thousands of images, which are actually just URLs. I'm rather new to the dev world but have found it very difficult to find a solution to this problem.
A majority of the database content is seeded using a custom rake and cron task. We're using the Dribbble API to pull in most of this content, including the images. Looking at the urls, it looks like Dribbble is using S3 to house their images. Perhaps that is part of the solution. (example url: https://d13yacurqjgara.cloudfront.net/users/4521/screenshots/2742352/nest_notifications.jpg).
I know this topic must be easy for someone out there, but I literally have no experience or success finding a solution. Help and suggestions would be greatly appreciated!
By request, here is a copy of the rake task:
namespace :dribbble do
desc "TODO"
task get_recent: :environment do
url="https://api.dribbble.com/v1/shots/?access_token=XXX"
response = HTTParty.get(url)
recent_shots = JSON.parse(response.body)
recent_shots.each do |s|
users_dribbbleid = s['user']['id']
shots_dribbbleid = s['user']['id']
existing_user = User.where(designer_id: users_dribbbleid)
#IS THERE AN EXISTING USER IN THE DATABASE? IF NO, THEN...
if existing_user.empty?
newuser = User.create(
designer_id: s['user']['id'],
designer_full_name: s['user']['name'],
designer_username: s['user']['username'],
designer_home_url: s['user']['html_url'],
designer_avatar_url: s['user']['avatar_url'],
designer_bio: s['user']['bio'],
designer_location: s['user']['location'],
designer_bk_count: s['user']['buckets_count'],
designer_comments_received_count: s['user']['comments_received_count'],
designer_follower_count: s['user']['followers_count'],
designer_is_following_count: s['user']['followings_count'],
designer_made_likes_count: s['user']['likes_count'],
designer_received_likes_count: s['user']['likes_received_count'],
designer_project_count: s['user']['projects_count'],
designer_rebounds_received_count: s['user']['rebounds_received_count'],
designer_added_shots_count: s['user']['shots_count'],
designer_list_of_followers_url: s['user']['followers_url'],
designer_following_list_url: s['user']['following_url'],
designer_list_of_shots_url: s['shots_url']
)
newshot = Shot.create(
dribbble_id: s["id"],
title: s["title"],
description: s["description"],
width: s["width"],
height: s["height"],
images_hidpi: s["images"]["hidpi"],
images_normal: s["images"]["normal"],
images_teaser: s["images"]["teaser"],
viewcount: s["views_count"],
likes_count: s['likes_count'],
comments_count: s['comments_count'],
attachments_count: s['attachments_count'],
rebounds_count: s['rebounds_count'],
buckets_count: s['buckets_count'],
html_url: s['html_url'],
attachments_url: s["attatchments_url"],
buckets_url: s['buckets_url'],
comments_url: s['comments_url'],
likes_url: s['likes_url'],
projects_url: s['projects_url'],
animated: s['animated'],
tags: s['tags'],
user_id: newuser.id
)
commentresponse = HTTParty.get(s['comments_url']+"?access_token=XXX")
comments = JSON.parse(commentresponse.body)
comments.each do |c|
comments_dribbbleid = c["id"]
existing_comment = Comment.where(comment_id: comments_dribbbleid)
if existing_comment.empty?
newcomment = Comment.create(
comment_id: c["id"].to_s,
comment_created_at: c["created_at"],
body: c["body"],
user_avatar_url: c["user"]["avatar_url"],
user_id: c["user"]["id"],
user_name: c['user']['name'],
shot_id: newshot.id
)
end
end
#IF THERE IS AN EXISTING USER ALREADY, THEN CHECK IF THERE IS AN EXISTING SHOT. IF THERE IS NOT AN EXISTING SHOT, THEN...
else
existing_user = User.where(designer_id: users_dribbbleid)
existing_shot = Shot.where(user_id: existing_user[0].id)
if existing_shot.empty?
newshot = Shot.create(
dribbble_id: s["id"],
title: s["title"],
description: s["description"],
width: s["width"],
height: s["height"],
images_hidpi: s["images"]["hidpi"],
images_normal: s["images"]["normal"],
images_teaser: s["images"]["teaser"],
viewcount: s["views_count"],
likes_count: s['likes_count'],
comments_count: s['comments_count'],
attachments_count: s['attachments_count'],
rebounds_count: s['rebounds_count'],
buckets_count: s['buckets_count'],
html_url: s['html_url'],
attachments_url: s["attatchments_url"],
buckets_url: s['buckets_url'],
comments_url: s['comments_url'],
likes_url: s['likes_url'],
projects_url: s['projects_url'],
animated: s['animated'],
tags: s['tags'],
user_id: existing_user[0].id
)
commentresponse = HTTParty.get(s['comments_url']+"?access_token=XXX")
comments = JSON.parse(commentresponse.body)
comments.each do |c|
comments_dribbbleid = c["id"]
existing_comment = Comment.where(comment_id: comments_dribbbleid)
if existing_comment.empty?
newcomment = Comment.create(
comment_id: c["id"].to_s,
comment_created_at: c["created_at"],
body: c["body"],
user_avatar_url: c["user"]["avatar_url"],
user_id: c["user"]["id"],
user_name: c['user']['name'],
shot_id: newshot.id
)
end
end
end
end
end
end
end
`
Here is what I was trying to do:
new_set = set.map do |d|
{ id: d.id, first_name: d.firstname, last_name: d.lastname, full_name: d.full_name, score: d.score, photo: d.user.avatar(:medium), sex: d.sex, bio: d.bio, google_plus: d.google_plus, facebook: d.facebook, protocol: d.protocol, verified: d.verified, excellence: d.excellence, verified_at: d.verified_at, excellence_at: d.excellence_at, protocol_at: d.protocol_at, educations: d.educations, qualifications: d.qualifications, services: d.services, branches: d.branches, reviews: d.dispenser_reviews.where(:approved=>true) }
end
Now when I try new_set.to_json I get escape quotes.
When I run new_set.as_json I get hash rockets.
Is there any way to get valid JSON including the information in new_set, above?
I have a task that I did not build but is no longer working. i am new to ruby on rails and have not found a solution for this problem yet.
when i run the task i Get:
this is the task:
desc "Archive Loads/Trucks that have expired."
task :expire_old_posts => :environment do
expired_loads = []
loads = Load.where("pickup < NOW()")
loads.each {|load| expired_loads << load.attributes }
ArchivedLoad.create( expired_loads )
loads.delete_all
end
little Debugging thru console
Confirms there are 120530 loads to transfer:
loads = Load.where("pickup < NOW()").count
2014-07-23 12:55:56 DEBUG -- (149.8ms) SELECT COUNT(*) FROM "loads" WHERE (pickup < NOW())
=> 120530
create the empty array:
expired_loads = []
=> []
run the where command
loads = Load.where("pickup < NOW()")
lots and lots of records... i limited it to two for testing
1.9.3-p547 :006 > loads = Load.where("pickup < NOW()").limit(2)
2014-07-23 13:02:07 DEBUG -- Load Load (74.2ms) SELECT "loads".* FROM "loads" WHERE (pickup < NOW()) LIMIT 2
=> [#<Load id: 18398947, user_id: 11074, origin: #<RGeo::Geographic::SphericalPointImpl:0x595f056 "POINT (-80.48237609863281 37.772544860839844)">, dest: #<RGeo::Geographic::SphericalPointImpl:0x595ec64 "POINT (-78.30302429199219 40.295894622802734)">, length: 48, comments: "~PostEverywhere_20140721140916~", ltl: false, rate: nil, delivery: "2014-07-22 17:00:00", pickup: "2014-07-21 17:00:00", weight: 48, equipment_id: 8, covered: false, created_at: "2014-07-21 19:16:16", updated_at: "2014-07-21 19:16:16", owner: nil, deleted: false, origin_city: "ronceverte", origin_state: "wv", dest_city: "martinsburg", dest_state: "pa">, #<Load id: 18398948, user_id: 11074, origin: #<RGeo::Geographic::SphericalPointImpl:0x553cd2a "POINT (-81.035400390625 37.384891510009766)">, dest: #<RGeo::Geographic::SphericalPointImpl:0x553c9d8 "POINT (-79.80570983886719 40.317527770996094)">, length: 48, comments: "~PostEverywhere_20140721140916~", ltl: false, rate: nil, delivery: "2014-07-22 17:00:00", pickup: "2014-07-21 17:00:00", weight: 48, equipment_id: 8, covered: false, created_at: "2014-07-21 19:16:16", updated_at: "2014-07-21 19:16:16", owner: nil, deleted: false, origin_city: "princeton", origin_state: "wv", dest_city: "greenock", dest_state: "pa">]
Really not sure what the << is but i assume this is just distributing the attributes so that they can be saved in the other table
loads.each {|load| expired_loads << load.attributes }
Errors here with
**NoMethodError: undefined method `<<' for nil:NilClass**
Next line is: Saves them to archived_loads table and deletes from loads table
ArchivedLoad.create( expired_loads )
loads.delete_all
Why not use #map instead? expired_loads = loads.map(&:attributes) or better yet just create a method in Load to archive them e.g.
class Load
scope :expired_loads, -> {where("pickup < NOW()")}
def self.archive_now
ArchiveLoad.create(expired_loads.map(&:attributes))
expired_loads.delete_all
end
end
Then you can call Loads.archive_now I am unsure of any of your structure this is just a suggestion as to a more concise implementation.
It also might be prudent to post the create method of your ArchivedLoad in case you have utilized the << method inside of there as well. If you have not implemented some kind of a custom create method I think you need a iteration instead such as
expired_loads.map(&:attributes).each{|load| ArchiveLoad.create(load)}
Also << is similar to push it adds an object to the end of an Array
When hitting the "Authorize" button, I get "Called id for nil"
Here is the line where the problem is occurring in my authorizations controller:
46 auth = authorization.authorize
Auth is coming up nil on the error page:
Local Variables
auth nil
Here are my request parameters:
{"utf8"=>"✓", "authenticity_token"=>"0m07v0jefxjeMOMt7U5rjRMJj0qhA27nBsamwKvHSMw=",
"client_id"=>"159c4b355fdef4a8e2887734f2f95af42d6b1199ddf94bb8a0fffb10bd3de0c4",
"redirect_uri"=>"http://localhost:3001/users/auth/provider/callback",
"state"=>"3b654057f568f5f542bfea92f07c9403fcfdc80a7a3208e4", "response_type"=>"code",
"scope"=>"public_read", "commit"=>"Authorize", "action"=>"create",
"controller"=>"oauth/authorizations"}
Also, here is what the #pre_auth variable contains when viewing the Authorize/Deny Form:
#<Doorkeeper::OAuth::PreAuthorization:0x007fc83c8d7a28 #server=
<Doorkeeper::Config:0x007fc83c0a3640 #orm=:active_record, #authenticate_resource_owner=
<Proc:0x007fc83c0a34d8#/Users/austen/sites/provider/config/initializers/doorkeeper.rb:7>,
#access_token_expires_in=nil, #enable_application_owner=true,
#confirm_application_owner=true, #default_scopes=public_read,
#optional_scopes=public_write private_read private_write, #scopes=public_read public_write
private_read private_write>, #client=#<Doorkeeper::OAuth::Client:0x007fc83c8d7a78
#application=#<Doorkeeper::Application id: 1, name: "WhiteDeals", uid:
"159c4b355fdef4a8e2887734f2f95af42d6b1199ddf94bb8a0f...", secret:
"d21e16cc50873d60a3f3aacf421c84766e9c183ea7d989f70e6...", redirect_uri:
"http://localhost:3001/users/auth/provider/callback", created_at: "2013-03-22 02:15:55",
updated_at: "2013-03-23 06:33:29", owner_id: 1, owner_type: "User">>,
#response_type="code", #redirect_uri="http://localhost:3001/users/auth/servant/callback",
#scope=nil, #state="3b654057f568f5f542bfea92f07c9403fcfdc80a7a3208e4", #error=nil>