pjf / WebService-HabitRPG

Access the HabitRPG API from Perl
8 stars 5 forks source link

$user->{profile}{name} not always valid #1

Closed oneandoneis2 closed 11 years ago

oneandoneis2 commented 11 years ago

I created my habitrpg account via my Facebook profile. When I run hrpg status I get:

Use of uninitialized value in concatenation (.) or string at /home/djh/perl5/perlbrew/perls/perl-5.14.2/bin/hrpg line 73. Hark, ! (Lv 1) ...

Running curl --compressed -H "Content-Type:application/json" -H 'x-api-user: {user key}' -H 'x-api-key: {api key}' https://habitrpg.com/api/v1/user and checking the returned JSON, the only place where my name appears is within auth.facebook

pjf commented 11 years ago

D'oh! I've never used HabitRPG using facebook auth.

I might tweak that to use a cascading set of options (profile name, facebook name, 'an adventurer').

pjf commented 11 years ago

Just to check, is it {auth}{facebook}{name} where your name appears? (My auth only has a local section, with username, email, etc)

pjf commented 11 years ago

Should be fixed in dev, at least insofar as not displaying an ugly warning. (You now have 'Hark, adventurer!')

oneandoneis2 commented 11 years ago

Cheers!

For reference, here's a (slightly expurgated) example of the JSON I get:

{"auth":{"facebook":{"provider":"facebook","id":"..........","username":"OneAndOneIs2","displayName":"Dominic Humphries","name":{"familyName":"Humphries","givenName":"Dominic","middleName":null},"gender":"male","profileUrl":"http://www.facebook.com/OneAndOneIs2","emails":[{"value":null}],"_raw":"{\"id\":\"..........\",\"name\":\"Dominic Humphries\",\"first_name\":\"Dominic\",\"last_name\":\"Humphries\",\"link\":\"http:\/\/www.facebook.com\/OneAndOneIs2\",\"username\":\"OneAndOneIs2\",\"location\":{\"id\":\"111126958910952\",\"name\":\"Worthing, West Sussex\"},\"quotes\":\"Once upon a time at home\r\nI sat beside the telephone\r\nWaiting for someone to call me through\r\nWhen at last it didn't ring I knew it wasn't you\",\"sports\":[{\"id\":\"107874725900895\",\"name\":\"Scuba diving\"},{\"id\":\"109368782422374\",\"name\":\"Running\"},{\"id\":\"105788652787522\",\"name\":\"Swimming\"}],\"gender\":\"male\",\"timezone\":0,\"locale\":\"en_US\",\"verified\":true,\"updated_time\":\"2012-06-16T17:23:29+0000\"}","_json":{"id":"..........","name":"Dominic Humphries","first_name":"Dominic","last_name":"Humphries","link":"http://www.facebook.com/OneAndOneIs2","username":"OneAndOneIs2","location":{"id":"111126958910952","name":"Worthing, West Sussex"},"quotes":"Once upon a time at home\r\nI sat beside the telephone\r\nWaiting for someone to call me through\r\nWhen at last it didn't ring I knew it wasn't you","sports":[{"id":"107874725900895","name":"Scuba diving"},{"id":"109368782422374","name":"Running"},{"id":"105788652787522","name":"Swimming"}],"gender":"male","timezone":0,"locale":"en_US","verified":true,"updated_time":"2012-06-16T17:23:29+0000"}},"timestamps":{"created":1363699301804,"loggedin":"2013-03-19T13:21:41.804Z"}},"balance":1,"dailyIds":["ded6028c-6d04-46e7-9dfb-dcb4996e1b48","2047f578-2e5a-4985-b9ef-1269695ff975"],"flags":{"customizationsNotification":true,"itemsEnabled":false,"partyEnabled":false},"habitIds":["7dca9ea7-4cb3-4aa4-b786-26668986de3f","2d17d7ae-df11-4aff-a869-aff0b4e5f260","2f1a911b-ff07-40c0-8408-ad2065203b3f","b950d00f-906d-4edb-a30b-085e9b0c1f9b","6670a2d2-09e7-456a-9a16-0d38af0e524c","9d622358-ce38-462f-bed7-46492a47f3ca"],"history":{"todos":[{"date":1363860173852,"value":-2.025956704627065}],"exp":[{"date":1363860173852,"value":7.5}]},"items":{"weapon":0,"armor":0,"head":0,"shield":0},"lastCron":1363860173852,"party":{"current":null,"invitation":null},"preferences":{"gender":"m","skin":"white","hair":"brown","armorSet":"v1","dayStart":0,"showHelm":true},"rewardIds":["55ad20fb-904c-404e-becf-1d9ea5786cea","048d5037-f0e3-410b-8fa5-52c3584ed878"],"stats":{"exp":7.5,"gp":1,"hp":45.9,"lvl":1,"toNextLevel":150,"maxHealth":50},"tasks":{"048d5037-f0e3-410b-8fa5-52c3584ed878":{"type":"reward","text":"Cake","notes":"But only buy if you have enough gold - you lose HP otherwise.","value":10,"id":"048d5037-f0e3-410b-8fa5-52c3584ed878"},"2047f578-2e5a-4985-b9ef-1269695ff975":{"completed":false,"history":[{"date":1363860173910,"value":-2.025956704627065}],"id":"2047f578-2e5a-4985-b9ef-1269695ff975","notes":"","repeat":{"su":true,"m":true,"t":true,"w":true,"th":true,"f":true,"s":true},"text":"Empty litter tray","type":"daily","value":-2.025956704627065},"2d17d7ae-df11-4aff-a869-aff0b4e5f260":{"type":"habit","text":"Write some (non-work) code","notes":"","value":0,"up":true,"down":true,"id":"2d17d7ae-df11-4aff-a869-aff0b4e5f260"},"2f1a911b-ff07-40c0-8408-ad2065203b3f":{"type":"habit","text":"Read up on Haskell","notes":"","value":0,"up":true,"down":true,"id":"2f1a911b-ff07-40c0-8408-ad2065203b3f"},"55ad20fb-904c-404e-becf-1d9ea5786cea":{"type":"reward","text":"1 Episode of Game of Thrones","notes":"-- Rewards: Treat Yourself! --\nAs you complete goals, you earn gold to buy rewards. Buy them liberally - rewards are integral in forming good habits.","value":20,"id":"55ad20fb-904c-404e-becf-1d9ea5786cea"},"6670a2d2-09e7-456a-9a16-0d38af0e524c":{"type":"habit","text":"Read up on JS","notes":"","value":0,"up":true,"down":true,"id":"6670a2d2-09e7-456a-9a16-0d38af0e524c"},"7dca9ea7-4cb3-4aa4-b786-26668986de3f":{"type":"habit","text":"Stretch","notes":"","value":0,"up":true,"down":true,"id":"7dca9ea7-4cb3-4aa4-b786-26668986de3f"},"9d622358-ce38-462f-bed7-46492a47f3ca":{"type":"habit","text":"Gym","notes":"","value":0,"up":true,"down":true,"id":"9d622358-ce38-462f-bed7-46492a47f3ca"},"b950d00f-906d-4edb-a30b-085e9b0c1f9b":{"type":"habit","text":"Read up on Perl","notes":"","value":0,"up":true,"down":true,"id":"b950d00f-906d-4edb-a30b-085e9b0c1f9b"},"c1ef53f0-d65a-471a-96a9-a67e3c9a3e80":{"completed":false,"id":"c1ef53f0-d65a-471a-96a9-a67e3c9a3e80","notes":"","text":"Kill BM server","type":"todo","value":-2.025956704627065},"ded6028c-6d04-46e7-9dfb-dcb4996e1b48":{"completed":false,"history":[{"date":1363860173989,"value":0}],"id":"ded6028c-6d04-46e7-9dfb-dcb4996e1b48","notes":"","repeat":{"su":true,"m":true,"t":true,"w":true,"th":true,"f":true,"s":true},"text":"Meditate","type":"daily","value":1}},"todoIds":["c1ef53f0-d65a-471a-96a9-a67e3c9a3e80"],"id":"...................................."}

Seems to be a fair amount of redundancy in there, but {auth}{facebook}{displayName} looks like your best bet.

Dominic

On Thu, 2013-03-21 at 04:08 -0700, Paul Fenwick wrote:

Should be fixed in dev, at least insofar as not displaying an ugly warning. (You now have 'Hark, adventurer!')

— Reply to this email directly or view it on GitHub.

pjf commented 11 years ago

Thank you! v0.03 has been pushed to the CPAN with these changes.

You should be able to update with cpanm hrpg once all of CPAN's index files update. But if you're not patient enough for that to happen, you can download direct with:

cpanm http://www.cpan.org/authors/id/P/PJ/PJF/WebService-HabitRPG-0.03.tar.gz

Many thanks!